【发布时间】:2016-05-16 00:53:57
【问题描述】:
以下代码在我将其放在服务器上后不起作用,我在本地环境中也有类似的代码,它运行良好,有什么想法吗?
编辑:我确实将我的 gmail 设置设置为“不太安全”
<?php
$setid = $_POST['setid'];
$promo = $_POST['promo'];
echo "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:";
echo "<br><br>";
echo $promo;
$message= "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:"."<br><br>".$promo;
require "phpmailer/class.phpmailer.php";
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "xxx@example.com";
$mail->Password = "mypass";
// Compose
$mail->SetFrom("jghh@ghh.ca");
$mail->AddReplyTo("ghh@ghh.ca");
$mail->Subject = "TryIt";
$mail->MsgHTML($message);
// Send To
$mail->AddAddress("receiver@hotmail.com", "Recipient Name");
$result = $mail->Send();
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
?>
这是我在网络中得到的 -> 预览:
先生,您的套装 ID 是 100065,您有资格享受以下优惠:
当前促销:下次访问可享受 15% 的折扣!SMTP 错误:无法验证。
【问题讨论】:
-
希望您没有在这里发布您的真实密码...
$mail->Password = "YOUR PASS" -
您使用的是非常旧的 PHPMailer 版本,而您还没有read the docs。