-1

I have a very simple contact form and a very simple php mail script. But when I tried to send it to the specified email address, I did not receive the test mail.

Below are my codes:

HTML Form

    <div class="form" >
    <form action="mail.php" method="post">
    Email: <input type="text" name="email" size="38"><br>
    詢問主旨:<input type="text" name="subject" size="36"><br>
    <div class="queryTitle">
    詢問內容
    </div>
    <br>
    <textarea name = "message" rows="6" cols="37">

    </textarea>
    <br>
    <input name = "submitted" type="submit" value="傳送">
    </form>
    </div>

Php script:

 <?php
 if (isset($_REQUEST['submitted'])) {
   if (empty($errors)) { 
   $from = "From: ".$_REQUEST['email']."\r\n"; //Site name
   // Change this to your email address you want to form sent to
   $to = "verymeanguy2@gmail.com"; 
   $subject = $_REQUEST['subject'];

   $message = $from." ".$_REQUEST['message'];
   mail($to,$subject,$message,$from);
   }
 }
 ?>

Could it be that Gmail blocked my mail? If so, how can I devise a script that can send mails to the popular mails?

Thanks in advance!

Jason

PS: I am hosting mine on heliohost's free Stevie server, if that accounts for something.

lolka_bolka: yes, mail() was called and adding an echo in front of mail function prints 1. And it's not in spam. Len_D: it did print anything, so I think mail was called and returned true. Anthony: how do I ensure that?


I just want to report back my testing. It seems that Gmail blocks Yahoo mail address sender for some reason. When the header is a Gmail address or even a bogus made-up address, Gmail can receive no problem. Yahoo mail on the other hand can receive mail with no problem at all. Anyone can shed a light on that?

Jason Ching
  • 1,037
  • 4
  • 19
  • 27

1 Answers1

1

When mail returns true (or 1), it means it did correctly what it tried to do. But doesn't always mean it sent mail at all.

the mail() funciton uses "sendmail" to actually send the email. If sendmail is configured to send mail, then that's what will happen (it everything went ok).

However, by defult, sendmail stores mail in the server. It "simulates" a real sendmail.

From my personal experience, I recommend PHPMailer. It's easy to use, it's much easier to check for errors (check if the email was sent, and if not, get infomation about the problem).

Example:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.server.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "email@domain.com";
$mail->Password = "password";

$mail->From = "email@domain.com";
$mail->FromName = "auto";
$mail->AddAddress("example@example.net", "Name of example user"); //send to....
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";

$mail->Subject = "=?UTF-8?B?".base64_encode(stripslashes($asunto))."=?=";
$mail->Body    = stripslashes($mensaje);

if(!$mail->Send()){
    echo "Message could not be sent. <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    return true;
} else {
    echo "Message has been sent";
    return false;
}

Hope it helped :)

DevPGSV
  • 191
  • 8