不使用 SMTP 的 PHPmailer

标签 php phpmailer

我已将 PHPMailer 文件夹添加到我的网络服务器上的根文件夹中,但我只是收到一个与 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();

但我收到一条错误消息,提示 “无法发送邮件。邮件错误:您必须至少提供一个收件人电子邮件地址。”

最佳答案

我注释掉了 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';
}
?>

关于不使用 SMTP 的 PHPmailer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32427920/

相关文章:

php - Joomla UTF-8 编码在打开邮件时失败

php - 发送带有 mysql 获取记录的电子邮件

php - 使用 PHPMailer 发送电子邮件 - 在正文中嵌入图像

php - Laravel 回显服务器在 web 上工作,但不使用 api 进行身份验证

javascript - 检查时差是否小于 45 分钟并运行函数 - AngularJS

php - mysql无限主键自增

PHPMailer - 无法验证

php - Codeigniter:DB order by effects 两个数据库查询

php - 使用 insert 到 mySQL 时编码不起作用,ä (ä) 变为 ¤(¤)

php - 批量邮件性能发送方式