首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用PHP从SMTP服务器发送电子邮件

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

Stack Overflow用户
提问于 2013-01-22 18:42:11
回答 8查看 779K关注 0票数 151
代码语言:javascript
复制
$from = "someonelse@example.com";
$headers = "From:" . $from;
echo mail ("borutflis1@gmail.com" ,"testmailfunction" , "Oj",$headers);

我在用PHP发送电子邮件时遇到了问题。我得到一个错误:SMTP server response: 530 SMTP authentication is required

我的印象是,你可以发送没有SMTP验证的电子邮件。我知道这封邮件可能会被过滤掉,但现在这并不重要。

代码语言:javascript
复制
[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

这是php.ini文件中的设置。如何设置SMTP?是否有不需要验证的SMTP服务器,或者必须自己设置服务器?

EN

回答 8

Stack Overflow用户

发布于 2013-01-22 18:46:57

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

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

代码语言:javascript
复制
$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

票数 194
EN

Stack Overflow用户

发布于 2013-01-22 19:21:48

代码语言:javascript
复制
<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL@gmail.com");

$message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";

$headers = "From: YOURMAIL@gmail.com";

mail("Sending@provider.com", "Testing", $message, $headers);
echo "Check your email now....&lt;BR/>";
?>

或者,有关更多详细信息,请参阅read on

票数 62
EN

Stack Overflow用户

发布于 2013-12-03 05:52:08

对于Unix用户,邮件()实际上是使用Sendmail命令发送电子邮件。您可以更改环境,而不是修改应用程序。msmtp是与Sendmail兼容的命令行界面语法的SMTP客户端,这意味着它可以用来代替Sendmail。它只需要对您的php.ini进行很小的更改。

代码语言:javascript
复制
sendmail_path = "/usr/bin/msmtp -C /path/to/your/config -t"

然后,即使是低级的mail()函数也可以使用SMTP work。如果你想在不修改应用程序的情况下将现有的应用程序连接到像sendgrid或mandrill这样的邮件服务上,它是非常有用的。

票数 49
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14456673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档