简体   繁体   中英

PHP Mail Function is not working

I am having trouble sending email with the php mail function. I can't figure out what the cause might be. The script gives no errors even with strict error reporting. I am using 000webhost to test the system.

Strange thing is I've written much more complicated email systems in the past that have not given me any problems. I'm hoping somebody here can point me in the right direction. Thanks! :)

$look ="SELECT * FROM `contact` ORDER BY `id` DESC LIMIT 1";
$result = mysql_query ($look);
while ($row = mysql_fetch_assoc($result)) {

echo $row['first_name'] . "<br/>";
echo $row['email'] . "<br/>";
echo $row['message'] . "<br/>";

$to= 'xxx@xxx.com';
$subject= "Mail from your portfolio website";
$txt=$row['message'] . '<br/><br/>' . $row['email'] . '<br/>' . $row['first_name'] .      $row['last_name'];
$headers = "Reply-To: xxxx@myproject.com" . "r\n";

mail ($to, $subject, $txt, $headers);
}

sorry for the following questions but are needed to avoid some headaches:

  1. Does you're query work? You may test this in your database.
  2. Are you connected to your DB?
  3. Does your server support mailing?

Then, if all these question have positive answers, you could add at the end of your code this two rows:

$mail_sent = @mail( $to, $subject, $txt, $headers );
echo $mail_sent ? "sent mail" : "Impossible to send mail"; 

Let me know the results of this test.

EDIT
as said basant rijal, the while it's useless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM