在很久很久以前这是一个简单的事情,但是现在好像不太简单了,不过还是可以搞定的。

第一步:在godaddy上开通一个对应自己域名的邮箱。点击“My Products”,然后打开“Email & Office”,点击 Office 365 Starter Email(这个没有的话需要购买一下,一般是随Hosting附送的) 后面的“Set up”,然后按提示设置好就可以了

第二步:在设置过程中,我们需要在域名的DNS解析中添加几条CNAME记录,

主机(Host):smtp;
记录类型(Type):CNAME;
记录值(TXT value):smtp.secureserver.net
主机(Host):smtp;
记录类型(Type):CNAME;
记录值(TXT value):smtpout.secureserver.net
主机(Host):smtp;
记录类型(Type):CNAME;
记录值(TXT value):v=spf1 a mx ptr include:secureserver.net -all

第三步:PHPMailer配置

$mail = new PHPMailer(true);
$mail->SMTPDebug = 1;
$mail->IsSMTP();
$mail->SMTPAuth = false;
$mail->Host = "localhost";
$mail->Port = 25;
$mail->SMTPSecure = "none";
$mail->SMTPOptions = array(
    "ssl" => array(
        "verify_peer" => false,
        "verify_peer_name" => false,
        "allow_self_signed" => true
    )
);
$mail->SetFrom("email @ your domain ", "your name");
$mail->AddAddress("the email your send to", "email user name");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->MsgHTML("Hi, this is an test email");
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}

第四步:测试发送,发送成功