简体   繁体   English

在服务器上发送电子邮件

[英]send email on server

I set up SMTP and smtp_port in php.ini file. 我在php.ini文件中设置了SMTP和smtp_port。 And it's already there. 它已经在那里。

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

Now, I am trying to send email by this: 现在,我正在尝试通过以下方式发送电子邮件:

$to      = 'email@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: email@example2.com' . "\r\n" .
        'Reply-To: email@example2.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

ERROR: 错误:

Message: mail(): Failed to connect to mailserver at
                 "ssl://smtp.gmail.com" port 465, verify your "SMTP" and
                 "smtp_port" setting in php.ini or use ini_set()

Is this because of authentication problem? 这是因为身份验证问题吗? I don't want to use PHPMailer . 我不想使用PHPMailer

you have to provide your gmail crendentials (login and password) to send mail via google smtp server 您必须提供您的gmail凭据(登录名和密码)才能通过Google smtp服务器发送邮件
the php mail() function does not provide this feature php mail()函数不提供此功能
i advise you to download and use this PHP Project : https://github.com/Synchro/PHPMailer With it you can do everything : gmail credentials, attach files, write mail with HTML.... 我建议您下载并使用此PHP项目: https : //github.com/Synchro/PHPMailer使用它,您可以执行所有操作:gmail凭据,附加文件,使用HTML编写邮件。
Hope that helps :) 希望有帮助:)

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

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