【问题标题】:How to send an SMS by using PHPMailer?如何使用 PHPMailer 发送短信?
【发布时间】:2019-05-23 09:54:53
【问题描述】:

我想使用 phpMailer 发送短信,我尝试进行所有配置但收到消息

警告:mail():SMTP 服务器响应:550 访问被拒绝 - 无效 C:\xampp\htdocs

中的 HELO 名称(参见 RFC2821 4.1.1.1)

下面是我的代码

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';
$mail = new PHPMailer(true);

try{                            
$mail->isSMTP();                                     
$mail->Host = 'mail.ku..e.com'; 
$mail->SMTPAuth = true;                             
$mail->Username = 'info@ku..e.com';              
$mail->Password = 'my password';                      
$mail->SMTPSecure = 'tls';                          
$mail->Port = 25;   
//$mail->Port = 25;

$to = "+25078.....@vtext.com";
$from = "info@k..e.com";
$message = "aaaaa";

$headers =  'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'From: Your name <info@ku..e.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
mail($to, '', $message, $headers);

} catch (Exception $e){
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

我是这样配置php.ini的

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.ku..e.com
; http://php.net/smtp-port
smtp_port=25

; For Win32 only.
; http://php.net/sendmail-from
;username = info@ku..e.com
;password = my password
;sendmail_from = info@ku..e.com

我使用 Inmotion 托管

请任何人都可以帮助我使用上述代码发送短信

【问题讨论】:

  • 因“550 Access denied”错误而在邮件客户端中禁用 SMTP 身份验证并检查端口

标签: php sms phpmailer


【解决方案1】:

呃,你没有使用 PHPMailer!您开始使用,但随后您放弃并改用mail()!替换这部分:

$headers =  'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'From: Your name <info@ku..e.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
mail($to, '', $message, $headers);

与:

$mail->isHTML();
$mail->addAddress($to);
$mail->setFrom('info@ku..e.com', 'Your Name');
$mail->Body = $message;
$mail->send();

然后您将正确使用 PHPMailer,并以我假设您的方式通过 SMTP 发送 有意的。

就发送 SMS 而言,PHPMailer 对此没有意见 - 如果您有可靠的电子邮件到 SMS 网关,那么它应该可以正常工作。也就是说,您的 SMS 网关不太可能需要 HTML 输入,因此您可能需要删除 $mail-&gt;isHTML(); 行以使其以文本/纯文本形式发送,并且您可能还想使用 $mail-&gt;CharSet = 'UTF-8';(并确保您的内容是在 UTF-8 中)。

【讨论】:

  • 您好 Synchro,我尝试使用您的观点,但是当我浏览我的文件时没有收到任何消息。我使用了 port=25 或 587
  • 如果你的意思是你得到一个空白页面,这意味着有一个致命错误 - 检查你的服务器的错误日志。 tls 模式将在端口 25 或 587 上工作,但与身份验证一起使用时,587 更常用于消息提交(出站)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-08
相关资源
最近更新 更多