我想使用php向我的服务器发送电子邮件。 我找到了以下基本示例::
<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "myname@ChemAlive.com";
$to_add = "myname@gmail.com";
$subject = "Test Subject";
$message = "Test Message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent OK";
}
else
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<input type='submit' name='submit' value='Submit'>
</form>
</p>
</body>
</html>
我也像这样配置我的php.ini:
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = myname@ChemAlive.com
然后重启我的apache。
然后我尝试通过浏览器中的php发送电子邮件,但没有任何反应。 我试图只使用php部分并直接在控制台中执行。
不是更好。
我试图直接在控制台中执行此操作:
sendmail bomble.laetitia@gmail.com < test.txt
在日志中我有:
Mar 30 11:49:19 ChemAlive postfix / pickup [24464]:71A6113470B9:uid = 1000 from = 3月30日11:49:19 ChemAlive postfix / cleanup [28761]:71A6113470B9:message-id =&lt; 20170330094919.71A6113470B9@ChemAlive.lan> 3月30日11:49:19 ChemAlive postfix / qmgr [1653]:71A6113470B9:from =,size = 263,nrcpt = 1(queue active) &#34; /var/log/mail.log" [readonly] 14400L,1586626C 14400
谢谢