1. Home
  2. Knowledge Base
  3. Website
  4. Website Tips
  5. Sample Mailing Script with External Server

Sample Mailing Script with External Server

When connecting to an external server such as GMail, Yahoo, Hotmail, etc. using a mailing script in Shared Server, Outgoing Mail Server settings must be authenticated and should only use the port 587 for security and privacy purposes.

++++
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = ‘ssl’; // secure transfer enabled REQUIRED for Gmail
$mail->Host = “smtp.gmail.com”;
$mail->Port = 587
$mail->IsHTML(true);
$mail->Username = “email@domainname.com”;
$mail->Password = “password”;
$mail->SetFrom(“example@gmail.com”);
$mail->Subject = “Test”;
$mail->Body = “hello”;
$mail->AddAddress(“email@domainname.com”);

if(!$mail->Send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
} else {
echo “Message has been sent”;
}
++++

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support