尝试为新注册的用户发送激活电子邮件,下面是到目前为止的代码:
$to = $email;
$subject = "Activate your account!";
$headers = "From: noreply@test.com";
$body = "..."
$mail($to, $subject, $body, $headers);
在phpacademy的教程中,讲师使用了
ini_set("SMTP", $server);
我不知道该做什么。我认为我的SMTP服务器应该是我的雅虎账户。我怎么发送邮件? 如果你打算用PHP邮件功能发送电子邮件,你必须首先在你的PC上设置一个SMTP服务器。另一种方法是,你可以使用一个类来完成这个任务,而不需要在你的PC上设置任何东西。已知PHP邮件器只需几行即可完成此操作:下面是一个来自项目站点的示例:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.example.com"; // SMTP server
$mail->From = "from@example.com";
$mail->AddAddress("myfriend@example.net");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! 'n'n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
官方网站:http://phpmailer.worxware.com
不,您的帐户与服务器不一样。您的$server
变量应该设置为SMTP服务器的合适的主机名或IP地址,如$server = "mail.myisp.net";
。
检查你的电子邮件客户端找到你自己的邮件服务器,或者问你的ISP。
$server
应该是您可以访问的运行SMTP服务器守护进程的机器的名称(或IP地址)。这应该与雅虎的服务(可能像smtp.yahoo.com)一起工作,但如果你要发送的电子邮件地址不是@yahoo.com,你需要提供一个用户名和密码。更常见的是使用本地服务器,就像你的办公室/学校为你配置的那样。或者,如果您运行的是unix操作系统,您可以完全跳过这一行,让它默认为localhost。
当我必须在用户注册后向用户发送激活电子邮件时,我考虑过相同的SMTP路由,但即使你设法实现它,使用SMTP也有某些缺点
- 邮件发送延迟。
- 垃圾邮件
- 配置等。
// Create a "server" in your "rack", then copy it's API key
define('POSTMARKAPP_API_KEY', 'xyz-blah-blah-blah');
// Create a "Sender signature", then use the "From Email" here.
// POSTMARKAPP_MAIL_FROM_NAME is optional, and can be overridden
// with Mail_Postmark::fromName()
define('POSTMARKAPP_MAIL_FROM_ADDRESS', 'email address that you are sending from-google apps email in my case');
define('POSTMARKAPP_MAIL_FROM_NAME', 'Description of the Sender name');
// Create a message and send it
Mail_Postmark::compose()
->addTo($to, $to)
->subject('whatever subject you want to put here for your email')
->messagePlain($pin_message)
->send();
是的,它很容易一旦你创建了一个虚拟服务器与postmarkapp。猜猜前1000封邮件是免费的,所以你可以尝试一下,如果不使用SMTP你的方式。在前1000个之后,我认为5000个价值7美元左右。真的很好,很便宜,我根本没有停工时间。
试一下。你会喜欢的。顺便说一下,我和邮戳没有任何关系,只是我喜欢使用他们的服务。看看我之前做这个的时候的问题。
PHP mail()函数发送电子邮件,但需要超过10分钟才能显示
如果你在Linux服务器上,你应该检查服务器作为SMTP服务器安装,如果没有,你最好配置一个在php.ini http://fr.php.net/manual/en/mail.configuration.php