我一直在开发一个页面,该页面会自动将Gmail帐户中的电子邮件发送到我网站特定用户的各种来源的邮件帐户。我在Localhost上完美地工作了。邮件由用户接收,并存储在Gmail帐户的“已发送邮件”中。
但是,只要我将其迁移到服务器,我们使用它就不再有效。代码如下: -
$mail = new PHPMailer();
try
{
$mail->CharSet = "UTF-8";
// telling the class to use SMTP
$mail->IsSMTP();
// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug = 0;
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the servier
$mail->SMTPSecure = "tls";
// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = 587;
// GMAIL username
$mail->Username = "xxxxxxx@gmail.com";
// GMAIL password
$mail->Password = "P4ssw0rd";
//Set reply-to email this is your own email, not the gmail account
//used for sending emails
$mail->SetFrom($from);
$mail->FromName = "XXX";
$mail->AddReplyTo('xxxxxxx@gmail.com' , 'XXX');
// Mail Subject
$mail->Subject = $subject;
//Main message
$mail->MsgHTML($message);
$mail->AddAddress($to, "");
$mail->Send();
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); //Boring error messages from anything else!
}
如果出现问题,在localhost上将Debug设置为1会产生预期的错误。但是,服务器上似乎没有任何事情发生。请帮忙。