Hello everyone:

I am trying to send a very simple email. I've tried everything in the header, still the mail() function doesn't email to my yahoo as well as my work email. Please find the code below and tell me what i am doing wrong here:

[code=php]<?php

$userid = $SESSION['username'];
$email_from = "$userid@gmail.com";
$to = $
POST['email'];
$subject = $POST['subject'];
$note = $
POST['note'];

if($to && $subject && $note) {
$body = $userid ." has invited you to a meeting for ". $subject ."\n\n". "NOTE: " . $note;

$headers = "From: " . $email_from . "\r\n";
$headers .= "To: " . $to . "\r\n";
$headers .= "Reply-To: ". $email_from . "\r\n";
$headers .= "X-Mailer: PHP / " . phpversion();

if(mail($to, $subject, $body, $headers)) {
echo "mail sent";
echo "<script type='text/JavaScript'>
setTimeout('window.close()',500);
</script>";
}
else {
print "mail not sent, please try later.";
}

} // end check if primary fields are filled

else {
?>

<style TYPE="text/css">
form {
font-family:arial;
font-size:12px;
font-weight:bold;
}
label { display:block;float:left;width:100px;clear:left; }
.clear { clear:both; }

</style>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
<label for="from">From:</label>
<?php echo $userid; ?>
<div class="clear"></div>
<label for="email">To:</label>
<input type="textbox" name="email" value="">
<div class="clear"></div>
<label for="subject">
Subject:</label>
<input type="textbox" name="subject" value="">
<div class="clear"></div>
<label for="note">Note: </label>
<textarea name="note"></textarea>
<div class="clear"></div>
<label>&nbsp;</label>
<input type="submit" name="btn_sendemail" value="Send!" class="btn" />
<div class="clear"></div>
<label>
required fields</label>
</form>[/code]

Edited by Kudose: Added [noparse]

[/noparse] tags

    Welcome to PHPBuilder!

    You need to add the Content-type header

      Thank you Kudose for reply but my question is for text email do we need content-type in the header.

      When I add: $headers = "Content-type: text/plain; charset=iso-8859-1" . "\r\n"; I still don't get my email @ yahoo, even @gmail, I got 'unknown sender'.

      Thanks you again.

        Many hosts require that the "From:" header's email address be a valid email account on that server, otherwise it will reject it as an attempt to use that server as a mail relayer. You may therefore have to set the From value to an email account for your hosting account, then use the "Reply-To:" header if you want replies to go somewhere else.

          Write a Reply...