我正在尝试在我的项目中使用phpmailer,但是gmail的SMTP设置似乎不正确。我之前提到过几个问题,但这些解决方案似乎都不适用于我。
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = ''; //gmail address
$mail->Password = ''; // gmail password
$mail->From = 'user@domain.com';
$mail->FromName = 'John Doe';
$mail->AddAddress('yadayada@gmail.com', 'Nick'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'subject';
$mail->Body = 'message body';
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('images/apache_pb.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
答案 0 :(得分:0)
你必须安装php_openssl.dll,如果你使用wampserver它很容易,搜索并应用PHP扩展。
在示例中更改此:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
然后您收到了一封来自gmail的电子邮件,其中提到了在此处启用“不安全访问应用程序”选项https://www.google.com/settings/security/lesssecureapps
答案 1 :(得分:0)
使用
package functions
// `getValue` should be `GetValue` to be exposed to other packages.
// It should start with a capital letter.
func GetValue() string{
return "Hello from this another package"
}