我正在使用PHPMailer发送电子邮件。当我使用gmail smtp时,它工作得很好,但当我尝试使用我的域smtp时我在屏幕上看到的是"发送消息!"但我根本没有收到任何电子邮件。说:"我试过使用调试器。"
We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
这是我的代码
<?php
date_default_timezone_set('Etc/UTC');
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
/* CONFIGURATION */
$crendentials = array(
'email' => 'xxxxx@example.com',
'password' => 'xxxxxx'
);
$smtp = array(
'host' => 'secure.ehostpk.com',
'port' => 465,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'ssl' //SSL or TLS
);
/* TO, SUBJECT, CONTENT */
$to = 'xxxxxx@example.com'; //The 'To' field
$subject = 'This is a test email sent with PHPMailer';
$content = 'This is the HTML message body <b>in bold!</b>';
$mailer = new PHPMailer();
//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPDebug = 2;
$mailer->SMTPAuth = true; //We need to authenticate
$mailer->Host = $smtp['host'];
$mailer->Port = $smtp['port'];
$mailer->Username = $smtp['username'];
$mailer->Password = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure'];
//Now, send mail :
//From - To :
$mailer->From = $crendentials['email'];
$mailer->FromName = 'Team'; //Optional
$mailer->addAddress($to); // Add a recipient
//Subject - Body :
$mailer->Subject = $subject;
$mailer->Body = $content;
$mailer->isHTML(true); //Mail body contains HTML tags
//Check if mail is sent :
if(!$mailer->send()) {
echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
echo 'Message sent !';
}
我找了很多,不知道该怎么办。如果有任何帮助,我将不胜感激。
我发现的一件事是,现在在大多数服务器上(尤其是cpanel服务器),你试图发送的电子邮件地址实际上必须在cpanel本身中创建,才能正常工作。
据我所知,脚本只将其路由到服务器和电子邮件帐户,然后从那里进一步路由,最后从服务器上的电子邮件帐户发送出去。因此,解决方案可能是在服务器中实际设置电子邮件地址。