【问题标题】:Mailer function does not work for gmail [closed]Mailer 功能不适用于 gmail [关闭]
【发布时间】:2015-08-28 10:22:52
【问题描述】:
if($sql)
{
require("master/PHPMailerAutoload.php");
$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 = "mail.php.net";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "krajesh@php.net";
$mail->Password = "password";
$mail->SetFrom("krajesh@php.net");
$mail->Subject = "subject";
$mail->Body = "<table cellpadding='0' cellspacing='0' border='0' bgcolor='#006699' style='border:solid 10px #006699; width:550px;'>
<tr bgcolor='#006699' height='25'>
<td><img src='logo.jpg' border='0' width='200' height='60' /></td>
</tr>
<tr bgcolor='#FFFFFF'><td>&nbsp;</td></tr>
<tr bgcolor='#FFFFFF' height='30'>
<td valign='top' style='font-family:Arial; font-size:12px; line-height:18px; text-decoration:none; color:#000000; padding-left:20px;'><b> Login details from $website_name </b></td></tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Username :  $email </td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Password :$password</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'><a href='$website_url/index.php?activate=".$actvateid."' style='font-family:Arial; font-size:11px; font-weight:bold; text-decoration:none; color:#2200CC;'>Click Here</a> to activate your account</td>
</tr>
</table>";
$mail->AddAddress($email);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "<script> window.location='index.php?sendsus'; </script>"; 
exit;
}
}

是我在代码中犯了错误还是我必须更改邮件功能本身? 邮件功能在本地工作,但不适用于 gmail.. 我也尝试过现场但 gmail 不工作..

【问题讨论】:

  • “不工作”绝不是一个充分的问题描述。
  • “邮件功能不适用于 gmail” - $mail-&gt;Host = "mail.php.net"; ?你那里也有账户? krajesh@php.net哇。你会认为你可以解决自己的邮寄问题。
  • 另外,这是stackoverflow.com/q/30664520的转贴
  • 不,我只是举个例子,但我在个人网站上有帐户.. 名称为 krajesh@xyzexample.com

标签: php phpmailer


【解决方案1】:

您使用了错误的主机和端口号使用此代码

$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 587;                   // set the SMTP port for the GMAIL server
$mail->SMTPSecure = "tls"; 

【讨论】:

猜你喜欢
  • 2015-05-26
  • 1970-01-01
  • 2021-09-11
  • 2016-11-06
  • 2022-11-17
  • 1970-01-01
  • 2012-06-26
  • 2015-11-27
  • 2018-07-18
相关资源
最近更新 更多