I would like to send an email using Gmail SMTP server through PHP Mailer.
I am running Zend Server Community Edition in my machine.
Following is my code (edited to hide certain confidential information).
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = "test msg";
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->Username = "<valid-id>";
$mail->Password = "<valid-password>";
$mail->SetFrom('[email protected]', 'Name');
$mail->AddReplyTo("[email protected]","Name");
$mail->Subject = "subject";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "halo:);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
Despite following thoroughly the example from PHP Mailer wiki page, I somehow couldn't manage to send the email accordingly.
This is the error message generated by the function:
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) The following From address failed: [email protected] Mailer Error: The following From address failed: [email protected]
Please advise me regarding this matter. Thank you.
b.c
- unexisting domain, so it don't want to route mails from this domain – CyberDem0n[email protected]
so that other mail servers see that theFrom
address is valid. You can set this email's quota to 0MB if you don't want it to receive any mail. – Bailey Parker