Web Hosting Talk







View Full Version : mail script wont send email


latheesan
12-12-2005, 05:06 PM
hello,

I coded this like in 10 minutes, (i know, took me longer than it should). For some absurd reason, it isnt working

please have a look at this code:

<?php

$friend_email = $_POST['friend_email'];
$subject = "checkout this site";
$your_name = $_POST['your_name'];
$your_email = $_POST['your_email'];
$message_str = $_POST['message'];
$message = "$your_name has recommended you to our site. He also said:<br><br>$message_str";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$_POST['friend_email'].' <'.$friend_email.'>' . "\r\n";
$headers .= 'From: Recommendation from <'.$your_email.'>' . "\r\n";

if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $friend_email)){
header("Location: /error.php?id=8");
}elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $your_email)){
header("Location: /error.php?id=9");
exit();
}else

if (($_POST['your_name']) && ($_POST['your_email']) && ($_POST['friend_email']) && ($_POST['message'])){
mail($friend_email, $subject, $message, $headers);
header("Location: /thankyou.php");
}else{
header("Location: /error.php?id=10");
}

?>

seems right to me, what do you think? it wont email anyone when i try to post values to this file called mail.php from "recommend_me.php" file

Oras
12-12-2005, 05:25 PM
What about the source of the form in "recommend_me.php", may be there is a mistake in naming a form field

latheesan
12-12-2005, 06:23 PM
true, let me double check the form part in recommend_me.php file

also, here is the code:

<form action="inc/mail.php" method="post">
<table border="0" cellspacing="0" cellpadding="0" class="body-text">
<tr>
<td align="left" valign="middle">
<b>Your Name</b></td>
<td align="left" valign="middle"></td>
<td align="left" valign="middle">
<input type="text" size="30" name="your_name"></td>
</tr>
<tr>
<td align="left" valign="middle">
<b>Your Email</b></td>
<td align="left" valign="middle"></td>
<td align="left" valign="middle">
<input type="text" size="30" name="your_email"></td>
</tr>
<tr>
<td align="left" valign="middle">
<b>Friend's Email</b></td>
<td align="left" valign="middle"></td>
<td align="left" valign="middle">
<input type="text" size="30" name="friend_email"></td>
</tr>
<tr>
<td align="left" valign="middle">
<b>Message</b></td>
<td align="left" valign="middle"></td>
<td align="left" valign="middle">
<textarea name="message" rows="3" cols="72">Type your message here</textarea></td>
</tr>
<tr>
<td align="left" valign="middle"></td>
<td align="left" valign="middle"></td>
<td align="left" valign="middle">
<input type="submit" value=" Send "></td>
</tr>
</table>
</form>

latheesan
12-12-2005, 08:37 PM
everything looks right to me, i couldnt figure out anything... can someone kindly assist me overcome this issue plz?

Oras
12-13-2005, 06:40 AM
Hi latheesan,
I think the problem is from the data your are sending, you may typed something with quota or double quota.
My suggestion is:
first add the function: addslashes as follows:

friend_email = addslashes($_POST['friend_email']);
$subject = "checkout this site";
$your_name = addslashes($_POST['your_name']);
$your_email = addslashes($_POST['your_email']);
$message_str = addslashes($_POST['message']);

This may help, if not, try to print these values before the mail function to check if there is something wrong, third ... put some echos at the script to check where the script is stopping.
Wish this help

Burhan
12-13-2005, 09:17 AM
I coded this like in 10 minutes, (i know, took me longer than it should). For some absurd reason, it isnt working

I think you mentioned the reason right there.


}else

latheesan
12-13-2005, 02:54 PM
fyrestrtr, i understand that i could be missing }else but im not too sure where :(

a little bit more help plz?

Oras
12-13-2005, 03:15 PM
}else
{
if (($_POST['your_name']) && ($_POST['your_email']) && ($_POST['friend_email']) && ($_POST['message'])){
mail($friend_email, $subject, $message, $headers);
header("Location: /thankyou.php");
}else{
header("Location: /error.php?id=10");
}

}

latheesan
12-13-2005, 04:56 PM
thanks oras :D

Oras
12-13-2005, 05:04 PM
my pleasure :)