Forum Moderators: coopster

Message Too Old, No Replies

Php Mail - Subject is repeating and showing wrong email address

php, php mail

         

rodriguez1804

10:44 pm on Apr 5, 2010 (gmt 0)

10+ Year Member



Hey guys,

I am having problems with something that I know must have a simple solution to it. I ve tried researching the web but have not found anything.

I am trying to send an email with php, everything shows up ok, except for two things.

1.) The subject is displaying twice.
- For example, if the subject is "Hello Joe!", the
mail will display "Hello Joe! Hello Joe!".

2.) Instead of the email showing up as example.com, it shows up as example.com@gator blah blah

Any suggestions as how to fix these issues?

Here's my mail function code below

function emailUser($sender2,$receiver2,$message2){
$dbConn = new dbConnection();
$dbConn->connect();

$sender=$sender2;
$receiver=$receiver2;
$email=$dbConn->viewSessionEmail($receiver);
$dbConn->closeConn();
$subject=$receiver.', you have new email at example.com';
$message=$message2;
$date=date("y-m-j,H:i:s a");
$to=$email; //person who's going to receive the email.

$headers .= "From: example.com \r\n";
//$headers .= "Reply-To: ". $email. "\r\n";
$headers .= "Subject: ". $subject . "\r\n";
//$headers .= "CC: webmaster@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$sendMail = mail($to,$subject,$message,$headers);
if($sendMail){
echo "
<div align='center' style='margin-top:40px; font-type:bold; font-size:20px;'>Your email has been sent!
</div>";
}

}


I then just call this function with the required parameters, but it's screwing up. Thanks for the help!

Matthew1980

9:42 am on Apr 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there rodriguez1804,

The only thing as I can see that stick out a mile is the $headers var. Your building it correctly, but the initial declaration sould be $headers =. Only the subsequent ones to this need to be 'added' ie:-

$headers = "From: example.com \r\n";
$headers .= "Reply-To: ".$email."\r\n";

etc

I'm not sure why you do this either:-

$to=$email; //person who's going to receive the email.

Why reassign the var, just place the first one in:-

mail($email, ....);

As you are declaring in the mailheaders just make sure that you are actually having HTML specified within the doctype too, this has potential to mess things up, I'm not saying as this causes your issues, but it's good practice ;-p

Again with this too:-

$subject=$receiver.", you have new email at example.com";

I'm not saying that it matters, just that I always tend to use the double quotes around a string :)

$message=$message2; //just place this var directly into the mail function as a param :)

See how you get on, I'm intrigued as to why your subject repeats though, there's no loop anywhere is there ?

[EDIT] As this is a function you have created, why not get the return value as the html div "mail sent successfully" message instead of doing in within the function? Ie:-

$returnString = "Your HTML values here";

return $returnString;

Then when calling the function you just attach it to a suitably named var, and echo that when the routine has completed.

Just a thought...

Cheers,
MRb