Mailer problem from a php newbie


#1

Ok, im new to programming so i thought id start trying to learn php. What ive tried to do is create a mailer.php page that takes info from a form and then emails it to my email address. All well and good, it works, its fantastic, but i have one huge and annoying problem, i cant get the From address to appear when i recieve the email. It just says “Nobody”. The subject shows perfectly but not the From address. Take a look at the code:

<?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $date = date ("l, F jS, Y"); $time = date ("h:i A"); if (!isset($_REQUEST['email'])) { header( "Location: contact.html" ); } elseif (empty($name) || empty($email) || empty($repeat) || empty($comments)) { header( "Location: error.html" ); } else { mail( "michaelalanthorn@hotmail.com", "Feedback Form Results", "$messagenName: $namenEmail Address: $emailnRepeat Email: $repeatnEmail Type: $typenFeedback: $commentsnDate: $datenTime: $time" ); header( "Location: confirm.html" ); } ?>

I need the information $email as the From address so i can then simply reply to the person sending the email. I have tried putting the information just after the mail and just before the sendto email address… and various other place, but it just wont work!!! Some help please before i pull all my hair out before im 23!!!

:evil:

Cheer!!!


#2

mail in manual:
http://www.php.net/manual/en/function.mail.php

here is some basic header stuff that I use for sending an MIME email message in UTF8 encoding.

$headers = "To: $to rn";
$headers .= "From: sendEmailProgram <someone@abc.com>rn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=utf8rn";

You could ask in the form for the users email address and simply insert it into the “From:” field with their first and Last Name

Ex: $headers .= "From: $fName $lName <$email>rn";


#3

thats fair enough but where do i put it??? ive tried putting “From: $email” in various places and it doesnt work!!!

More the question is: where do u specify the From address???


#4

My error email function

function sendSqlErrorEmail($sql, $to, $sqlError)
{
    $subject = "Query Failure";
    $headers = "To: $to rn";
    $headers .= "From: sendEmailProgram <*****@*****.com>rn";
    $headers .= "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=utf8rn";

    $message = "<P>The query $sql failed because $sqlError.</P>";

    // send mail
    mail($to, $subject, $message, $headers);
}

and it is called with

$resultID = mysql_query ($sql);
if ($resultID)
{
    //do something
}
else                                    // if errors in query
{
    sendSqlErrorEmail($sql, $contactInCaseOfError, mysql_error());
}

The From is part of the headers that you create for the mail(). Don’t forget to use the .= rather then =

the .= concatinates to the end.

what does this do for you… gives you a working example to base your off of (Do not copy and paste. This is my code. Besides it doesn’t fit your problem exactly.) Between my last answer and this example you should be able to figure it out. If not - let me know.