【发布时间】:2015-09-26 06:55:15
【问题描述】:
我在 gmail 上为邮件设置了自定义域。
我在不同的托管服务提供商上托管了我的网站,我正在使用 CodeIgniter 和 PHP 通过我的帐户发送电子邮件。
启用通过我的 gmail 帐户发送邮件(从联系表)需要哪些设置? 我需要使用什么代码?
更新: 我尝试过的是以下内容: - 创建一个新的电子邮件帐户(@gmail.com,非自定义) - 启用两步验证 - 生成应用程序专用密码 - 用它来发送电子邮件 即使这样也行不通。
这是我正在使用的代码:
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.googlemail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'samesenderaccount@gmail.com'; // SMTP username
$mail->Password = 'appspecificpassword'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->Port = 465;
$mail->From = 'samesenderaccount@gmail.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('samesenderaccount@gmail.com', 'Info'); // Add a recipient
//$mail->AddAddress('ellen@example.com'); // Name is optional
$mail->AddReplyTo('other@gmail.com', 'From Try');
//$mail->AddCC('cc@example.com');
//$mail->AddBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
// Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body in bold!';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
【问题讨论】: