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<adam@adamplowman.co.uk>' . "\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
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 <someone@example.com>". The mail command may not parse this properly while talking with the MTA.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.