当前位置: 首页 > 知识库问答 >
问题:

从SMTP服务器用PHP发送电子邮件

娄阳舒
2023-03-14
$from = "someonelse@example.com";
$headers = "From:" . $from;
echo mail ("borutflis1@gmail.com" ,"testmailfunction" , "Oj",$headers);
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = someonelse@example.com

共有1个答案

萧宏远
2023-03-14

当您通过需要SMTP身份验证的服务器发送电子邮件时,您确实需要指定它,并设置主机、用户名和密码(如果不是默认的-25的话,可能还需要设置端口)。

例如,我通常使用的PHPMailer设置与此类似:

$mail = new PHPMailer();

// Settings
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com";    // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username";            // SMTP account username example
$mail->Password   = "password";            // SMTP account password example

// Content
$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';

$mail->send();

您可以在这里找到关于PHPMailer的更多信息:https://github.com/PHPMailer/PHPMailer

 类似资料:
  • 问题内容: 我正在尝试从PHP页面通过GMail的SMTP服务器发送电子邮件,但出现此错误: 身份验证失败[SMTP:SMTP服务器不支持身份验证(代码:250,响应:mx.google.com,为您提供服务,[98.117.99.235]大小为35651584 8位MIME STARTTLS增强的状态代码,编码方式)]] 有人可以帮忙吗?这是我的代码: 问题答案: // Pear Mail Li

  • 你好;我正在使用s.o上给出的答案进行smtp邮件;(如果搜索,相信这是第一个结果) 但我仍然没有收到邮件;任何人都可以帮助发现任何错误或提供替代解决方案吗?我已经使用了内置的邮件程序,但它没有被认证,请参阅 -

  • 我创建了下一个类: 我在我的服务中声明它是一项服务。yml 在我的控制器中,调用服务: 电子邮件已发送,但页面仍在加载30秒,我有一个来自开发人员工具栏的警报:加载Web调试工具栏时发生错误(404:未找到)。您想打开分析器吗?如果接受消息,Symfony分析器不显示任何错误。如果取消,消息开发人员工具栏不会出现。 我做错了什么? 非常感谢。

  • 我试图发送电子邮件使用gmail smtp使用javax.mail.下面是我的代码 代码工作正常当我在本地服务器上运行它时,但当我尝试在Elastic beanstek上运行它时(我的服务器在AWS EBS上运行),身份验证失败异常即将到来注意:我已打开从Google A/c设置访问不太安全的应用程序,但我仍然收到此错误 javax.mail.身份验证失败异常:534-5.7.14请通过您的网络浏

  • 我目前正在为某人做一个网站,我想在联系我们页面上添加一个表单,使用他们没有Php的网络托管服务器向他们的电子邮件地址发送消息。有人能帮我吗?我无法理解这个过程,以及如何使它安全并真正发挥作用。我必须在服务器上部署一些东西吗?或者我可以使用他们在那里的smpt服务器吗?如果是这样,我如何确保smtp服务器身份验证在客户端的devols上不可见。谢谢你!