开发者

Send Email from PHP Script

开发者 https://www.devze.com 2023-01-21 00:40 出处:网络
I wrote some code to send an email from my PHP script using PHPMailer. For some reason, the scripts isn\'t sending the messages.

I wrote some code to send an email from my PHP script using PHPMailer. For some reason, the scripts isn't sending the messages.


Here Is My Code:

<?php
require_once("PHPMailer/class.phpmailer.php");
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "admin@zbrowntechnology.com";
$mail->Password = "PASSHERE";
$mail->SetFrom = "admin@zbrowntechnology.com";
$mail->AddAddress("zach@zbrowntechnology.com.com");
$mail->Subject = "Confirm Web Lock Registration!";
$mail->Body = "Please confirm your Web开发者_运维问答 Lock Registration by clicking here!";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo "Message Sent!";
}
?>

This Is The Error Echoed:

SMTP Error: Could not connect to SMTP host. Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.


Your error message might be caused by the firewall settings on your server. This error message is commonly caused by a firewall blocking outgoing connections on the port.

You also should make sure that you have the openssl extension enabled.

Original Answer that you fixed:

You are sending to zach@zbrowntechnology.com.com which is not the address you want.

You need to remove the second .com and change it to zach@zbrowntechnology.com


I'm using PHPMailer too, just tried your settings, and got the same error. Here are my settings witch work for me (I show with ->> things witch you don't have, or are different for me)

$mail->PHPMailer = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
->> $mail->SMTPSecure = "ssl";
->> $mail->Host = "smtp.gmail.com"; //not ssl://smtp.gmail.com
$mail->Port = 465; etc...

Everything else is the same, except i don't use word wrap, but i checked, it's not causing the problem.


You need to specify gmail username and password because that is the what you are using in smtp settings:

$mail->Username = "email_address@gmail.com";
$mail->Password = "yourgmailpassword";


As a general tip, try turning on debugging:

$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

From SO: Debugging PHP Mail() and/or PHPMailer


Just as a bit of advise you might also want to try using Zend_Mail, you can use this happily without having to go the whole MVC route and it is very informative

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号