简体   繁体   中英

php mail() is not sending emails

I am using php mail to notify my subscribers of new blog posts.
Because my below function wasn't sending I decided to add an error catcher, and mail() returns true, and it shows my email address, however the email is not sent. Please help

$sql = "SELECT * FROM subscribers";
    while ($ste = mysqli_fetch_array(mysqli_query($con,$sql)))
    {
    $messager="
<html>
<head>
<title>Check out what's happening on my Blog this week</title>
<body>
";  
$date = date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s"),date("m"),date("d")-7));
    $sqli = "SELECT * FROM blog WHERE date > '$date' LIMIT 2";
    $res = mysqli_query($con,$sqli);
    while ($jw = mysqli_fetch_array($res))
    {
    $messager = $messager."<h2>$jw[header] by $jw[author]</h2><p>".substr($jw["text"], 0, 250)."..."."</p><br>";
    }
    $messager = $messager."</body></html>";
    // To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: <no-reply@zinteen.co.uk>';
$headers .= "X-Mailer: PHP/" . phpversion(); 
   $ma= mail("$ste[email]", "Check out what's happening on my Blog this week",
    $messager, $headers);
    if ($ma)
    die("should've worked.".$ste["email"]);
    }
}

Contact with server administator, or try to use SMTP with providing auth credentials

Very usefull mail class for php

http://phpmailer.worxware.com/index.php?pg=examplebsmtp

You should position your quotes another way:

$ma= mail($ste["email"], "Check out what's happening on my Blog this week",
$messager, $headers);

I changed them at your email.

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