Jeremy
Jeremy

Reputation: 350

PHPMail function: Won't change display name in mail

I'm currently working on an event registration form in which the user puts in his information and then the form sends it to us via PHPMail.

Everything is working fine, I receive all the inputs from the user, however, it seems that I can't change the display name of the sent mail.

My mailer code looks like this:

    $p_regist="registration<br /><br />";
    $p_receive="[email protected]";
    $p_sender="[email protected]";
    $p_subject="Registration".umw($_POST['f_name']).": ".$_POST['f_even'];
    $p_subject_user="Register Confirmation: ".$_POST['f_even'];
    $p_extra="from: $p_sender ";
    $headers .= 'From:Display Name here'."\r\n";
    mail($p_receive, $p_subject, $p_mail_text, $p_mail_check, $p_extra, $headers)
        or print "Could not send mail to receiver";
    mail($_POST['f_mail'], $p_subject_kunde, $headers,
         'Thank you for your registration!',   $p_mail_text)
        or print "could not deliver mail";
    $p_sent=1;

I also tried sending the mail in a separate PHP file.

How can I include the submitter's full name in the email message 's headers?

Upvotes: 0

Views: 938

Answers (3)

tripleee
tripleee

Reputation: 189487

You are putting in two From: headers but there can be only one.

Probably remove $p_extra altogether and put the formatted sender header in the regular $headers.

In addition, you need to audit your code for injection vulnerabilities. Basically, anything which comes from a POST will need to be vetted. In particular, make sure there are no newlines or other shenanigans in the input you are receiving from the user. For details, see e.g. PHP's mail(): What are potential issues to watch out for?

You would probably be better off using a proper mail library; the basic functionality in PHP is ugly, insecure, and hard to use.

Upvotes: 1

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

You need to send the Headers along with your Php mail code

$p_regist="registration<br /><br />";
$p_receive="[email protected]";
$p_sender="[email protected]";
$p_subject="Registration".umw($_POST['f_name']).": ".$_POST['f_even'];
$p_subject_user="Register Confirmation: ".$_POST['f_even'];
$header = "From: [email protected]\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n"; 

Upvotes: 0

Kevin Lab&#233;cot
Kevin Lab&#233;cot

Reputation: 1995

This is because email address is mandatory. The from format must be From: Display name <email@address>

Here is your $headers fixed :

$headers .= 'From: Display Name here <[email protected]>'."\r\n";

Upvotes: 1

Related Questions