PHP'发送电子邮件'但未收到

时间:2013-07-15 19:08:04

标签: php debugging email if-statement

坚持一个简单的PHP邮件的东西。任何人都可以找到我出错的地方。很乐意为你提供帮助。

<?php
$to = "example@website.co.uk";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mail($name, $email, $subject, $message);
if(mail($name, $email, $subject, $message)) { 
  echo "E-Mail Sent"; 
} else { 
  echo "There was a problem"; 
}  
?>

2 个答案:

答案 0 :(得分:2)

第一条评论几乎说了一切,如果你需要一个关于mail()函数的初学者友好教程,你应该看看PHP Sending E-mails

<?php
$to = "example@website.co.uk";
$name = 'From:'.$_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

if(mail($to, $subject, $message, $name)) { 
  echo "E-Mail Sent"; 
} else { 
  echo "There was a problem"; 
}  
?>

答案 1 :(得分:-2)

试试这个,它需要垃圾邮件打样等......

<?php
     $to      = 'example@example.com';
     $subject = $_POST['subject'];
     $message = $_POST['message'];
     $headers = 'From: contact@yoursite.com';

     mail($to, $subject, $message, $headers);
?>