how to send mail using phpmailer on xampp(如何在 xampp 上使用 phpmailer 发送邮件)
                            本文介绍了如何在 xampp 上使用 phpmailer 发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我一直在尝试使用 xampp 上的 php mailer 发送邮件,但我确实收到此错误消息无法发送消息.邮件程序错误:以下发件人地址失败:xxxx2@gmail.com:在未连接的情况下调用 Mail()
I have been trying to send a mail using php mailer on xampp and i do get this error saying Message could not be sent. Mailer Error: The following From address failed: xxxx2@gmail.com : Called Mail() without being connected
拜托,我需要有关如何解决此问题的帮助.这是我的代码;
please, i need help on how to fix this. Here is my code;
<?php
require( 'class.phpmailer.php' );
  $mail = new PHPMailer;
  $mail->IsSMTP();
  $mail->SMTPAuth = true;
  $mail->Host = "tls://smtp.gmail.com";
  $mail->Port = 25;
  $mail->Username = "xxxx@gmail.com";
  $mail->Password = "xxxxx";
  //Sending the actual email
  $mail->setFrom('xxxx2@gmail.com', 'Aaron');
  $mail->addAddress('xxxx2@gmail.com', 'Aaron');     // Add a recipient
  $mail->isHTML(false);                                  // Set email format to HTML
  $mail->Subject = 'Calculation form results from ';
  $mail->Body = 'testing...';
  if(!$mail->send()) {
    echo 'Message could not be sent. ';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
  }
?>
推荐答案
从 https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
                        这篇关于如何在 xampp 上使用 phpmailer 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:如何在 xampp 上使用 phpmailer 发送邮件
				
        
 
            
        
             猜你喜欢
        
	     - 带有通配符的 Laravel 验证器 2021-01-01
 - 正确分离 PHP 中的逻辑/样式 2021-01-01
 - 从 PHP 中的输入表单获取日期 2022-01-01
 - Laravel 仓库 2022-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - PHP Count 布尔数组中真值的数量 2021-01-01
 - SoapClient 设置自定义 HTTP Header 2021-01-01
 - 没有作曲家的 PSR4 自动加载 2022-01-01
 - Mod使用GET变量将子域重写为PHP 2021-01-01
 - 如何定位 php.ini 文件 (xampp) 2022-01-01
 
				
				
				
				