简体   繁体   English

在PHP中通过localhost发送电子邮件

[英]Sending an email via localhost in PHP

I'm trying to send an email through PHP. 我正在尝试通过PHP发送电子邮件。 It gives the following warning. 它给出以下警告。

Warning: mail() [function.mail]: Failed to connect to mailserver at 
"smtp.ntlworld.com" port 25, verify your "SMTP" and "smtp_port" setting in 
php.ini or use ini_set() in C:\wamp\www\wagafashion\customerside\BulkInquiry.php 
on line 1007

In php.ini, SMTP has been changed as follows. 在php.ini中, SMTP已作如下更改。

[mail function]
; For Win32 only.
SMTP = smtp.ntlworld.com
smtp_port = 25

; For Win32 only.
sendmail_from = tiny1999@gmail.com

After configuring php.ini, WAMP was restarted and it gave the above warning. 配置php.ini之后,WAMP重新启动,并给出了以上警告。 What other settings are to be made to send an email via localhost in PHP? 要通过PHP的本地主机发送电子邮件还有哪些其他设置?

Use PHPMailer instead: https://github.com/PHPMailer/PHPMailer 改用PHPMailer: https : //github.com/PHPMailer/PHPMailer

How to use it: 如何使用它:

require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';

$body = 'This is the message';

$mail->IsSMTP();
$mail->Host       = 'smtp.gmail.com';

$mail->SMTPSecure = 'tls';
$mail->Port       = 587;
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;

$mail->Username   = 'me.sender@gmail.com';
$mail->Password   = '123!@#';

$mail->SetFrom('me.sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycomp.com','no-reply');
$mail->Subject    = 'subject';
$mail->MsgHTML($body);

$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */

$mail->AddAttachment($fileName);
$mail->send();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM