如何使用php从shell发送邮件
我在sendmail.php中有以下代码:如何使用php从shell发送邮件,php,email,shell,Php,Email,Shell,我在sendmail.php中有以下代码: #!/usr/bin/php <?php $to = "testmail@gmail.com"; $subject = "TestSubject"; $body = "TestBody"; if (mail($to, $subject, $body)){ echo "Mail Sent"; }else { echo "Mail Failed"; } ?> 上面写着“邮件已发送”,但什么也没有发送。为什么会这样?谢谢tuo
#!/usr/bin/php
<?php
$to = "testmail@gmail.com";
$subject = "TestSubject";
$body = "TestBody";
if (mail($to, $subject, $body)){
echo "Mail Sent";
}else {
echo "Mail Failed";
}
?>
上面写着“邮件已发送”,但什么也没有发送。为什么会这样?谢谢tuongle建议我查看您的php.ini文件。也是经过审查, 您可能希望一次性检查代码,以确保您拥有所有必要的信息 如果我是在你的情况下,我会拿出我自己的代码,直接从php手册中插入示例代码,看看你的问题可能发生在哪里 试试下面的方法,看看你的邮件是否被发送出去了
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
您在哪个用户下尝试了该脚本?您是否在php.ini中配置了邮件服务器?
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>