0

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="mymail@testmail.com";
    $p_sender="mymail@testmail.com";
    $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?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Jeremy
  • 270
  • 5
  • 19
  • There are pieces missing, you are declaring a bunch of variables but never using them, and using a bunch of variables you are not declaring (or not showing us part of the code). – tripleee Aug 28 '14 at 07:30

3 Answers3

1

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 <you@email.com>'."\r\n";
Kevin Labécot
  • 2,005
  • 13
  • 25
  • Hi there, thanks! I have set the mail but it still doesn't change the display name in the mail – Jeremy Aug 28 '14 at 07:21
1

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.

Community
  • 1
  • 1
tripleee
  • 175,061
  • 34
  • 275
  • 318
0

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

$p_regist="registration<br /><br />";
$p_receive="mymail@testmail.com";
$p_sender="mymail@testmail.com";
$p_subject="Registration".umw($_POST['f_name']).": ".$_POST['f_even'];
$p_subject_user="Register Confirmation: ".$_POST['f_even'];
$header = "From: noreply@example.com\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"; 
Moeed Farooqui
  • 3,604
  • 1
  • 18
  • 23