【问题标题】:PHPmailer without using SMTP不使用 SMTP 的 PHPmailer
【发布时间】:2015-09-06 20:22:46
【问题描述】:

我已将 PHPMailer 文件夹添加到我的 Web 服务器上的根文件夹中,但我收到了一个与 SMTP 有关的错误。

有没有一种无需登录邮件账户即可使用 PHPMailer 的方法? 我可以让服务器将电子邮件发送到一个地址吗?

我正在搜索这个网站并找到了这个

$email = new PHPMailer();
$email->From      = 'you@example.com';
$email->FromName  = 'Your Name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();

但我收到一条错误消息,上面写着"Message could not be sent.Mailer Error: You must provide at least one recipient email address."

【问题讨论】:

  • 我刚收到一封来自谷歌的电子邮件,说他们阻止了 SMTP 尝试,猜猜这就是错误的来源......我会再试一次。但请回答我的问题
  • 同样的错误:无法发送邮件。邮件程序错误:SMTP 连接()失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  • 默认使用php的mail()
  • 它托管在我付费订阅的网络服务器上...我只是注释掉了所有 SMTP 行并保留了其他所有内容,它可以正常工作,我收到一封来自“Mailer from@example.com "
  • 是的,正在使用 mail(),当您已经为邮件服务器付费时,没有理由使用 gmail

标签: php phpmailer


【解决方案1】:

我注释掉了 SMTP 行,现在它可以工作了

<?php

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

//$mail->isSMTP();                                      // Set mailer to use SMTP
//$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
//$mail->SMTPAuth = true;                               // Enable SMTP authentication
//$mail->Username = '';                 // SMTP username
//$mail->Password = '';                           // SMTP password
//$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('name@domain.com', 'User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

【讨论】:

    【解决方案2】:

    Joseph Kreifels II 是正确的。

    具体请参见class.phpmailer.php 文件中的 cmets:

    /**
     * Sets Mailer to send message using SMTP.
     * @return void
     */
    public function IsSMTP() {
       $this->Mailer = 'smtp';
    }
    
    /**
     * Sets Mailer to send message using PHP mail() function.
     * @return void
     */
    public function IsMail() {
      $this->Mailer = 'mail';
    }
    
    /**
     * Sets Mailer to send message using the $Sendmail program.
     * @return void
     */
    public function IsSendmail() {
      if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
        $this->Sendmail = '/var/qmail/bin/sendmail';
      }
      $this->Mailer = 'sendmail';
    }
    

    因此,请务必从您的设置中删除$mail-&gt;IsSMTP();,但另外您可能需要添加$mail-&gt;IsMail();$mail-&gt;IsSendmail();,具体取决于您的服务器设置。

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 2012-05-21
      • 2014-09-16
      • 2022-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-24
      相关资源
      最近更新 更多