Search code examples
phpgmail

What is the right way to send PHP Mail Headers?


I have run into a weird problem. Some clients would like to be able to use gmail canned responses with emails submitted through their site's web form. Up until canned responses, everything has worked fine. Simply clicking "reply" on an email from the web form submission worked like a charm and replied to the sender. However, CannedResponses from Google Labs is proving to be a problem. Canned responses is auto replying to [email protected] (changed for privacy reasons, obviously) rather than the senders email address. Am I doing something wrong with the headers, or is there another workaround? Code below:

function send_mail($to, $subject, $from, $messageData=array()) {

    // Build the message here

    $mailheaders = "From: $from";
    $mailheaders .= "\r\n";
    $mailheaders .= "Reply-To: $from";

    return mail($to, $subject, $message, $mailheaders);
}

Edit for clarification: What I mean by auto replies being sent to [email protected] is my username at my dreamhost web server - ps0000.dreamhostps.com


Solution

  • While i strongly recommend you switch to a mailer library such as phpmailer or swiftmailer, in the short term you can fix it by using the -f parameter in your mail() function