Jump to content

Mail problem


adam291086

Recommended Posts

I have a mail script. The problem is the echo message ''Mail Failed'' is always echoed. The emails are still being sent. Any ideas

 

<?php


// db properties
$dbhost = '';
$dbuser = ''; 
$dbpass = '';
$dbname = '';
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($dbname);

$conn;
$sql = "SELECT * FROM generalContact";

 $result = mysql_query("$sql");


while($row = mysql_fetch_array($result))
 {
$message = $row['Message'];
$email = $row['email'];
$subject = $row['subject'];
$name = $row['firstName'];
}
echo $email;
echo $subject;
echo $message;
echo $name;

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email
$headers .= 'From: Adam<[email protected]>' . "\r\n"; // This is YOUR name and email

if(mail($email, $subject, $message, $headers)){
echo "Mail has been sent";
}else{
echo "Mail Failed";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/84489-mail-problem/
Share on other sites

Are you running this on windows?

 

Only this is mentioned on http://uk.php.net/manual/en/function.mail.php

 

Note: The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

As such, the to parameter should not be an address in the form of "Something <[email protected]>". The mail command may not parse this properly while talking with the MTA.

Link to comment
https://forums.phpfreaks.com/topic/84489-mail-problem/#findComment-430820
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.