简体   繁体   中英

PHP Mail Script working but email not arriving

I've written the following PHP script to send an email based on a forms input:

<?php

$to=$_POST["email"];

$subject=$_POST["subject"];

$message=$_POST["message"]."<br />".'<img src=imgdir/'.$_POST["banimg"].'"/><br /><br />'.'<img src=addir/'.$_POST["adimg"].'"/><br /><br />';

$from="foo@example.com";

$headers=array();
$headers[]="MIME-Version: 1.0";
$headers[]="Content-type: text/html; charset=iso-8859-1";
$headers[]="Content-Transfer-Encoding: 8bit";
$headers[]="From: ".$from;

$advertised=mail($to,$subject,$message,join("\n",$headers));

if ($advertised){
echo "Working";
}

?>

My echo "Working" returns as true, so the script is completing, however, the email is not being delivered.

Is there an issue within my code here?

Dustin

The php manual states that Multiple extra headers should be separated with a CRLF (\\r\\n).

It is possible that is a source of the problem. Aside from that, make sure that your email settings in php.ini are configured properly for the local server, and that a mta such as sendmail or smtp is installed and running on the server.

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