Home Ask Login Register

Developers Planet

Your answer is one click away!

bunnycode February 2016

PHP email form won't submit with different entered email address

Any idea why the [Enter email] field on this form will only reach me@me.com if the email entered matches me@me.com?

If I put in any other email address than the one listed in $to=, the email doesn't send.

$fieldname = 'images';
    if ($_POST){

    // we'll begin by assigning the To address and message subject

    $from = "<".stripslashes($_POST['email']).">";

// generate a random string to be used as the boundary marker

// now we'll build the message headers
$headers = "From: $from\r\n" .
           "MIME-Version: 1.0\r\n" .
           "Content-Type: multipart/mixed;\r\n" .
           " boundary=\"{$mime_boundary}\"\n";

Thank you for any help.

Edited to add pastebin


Eric J. February 2016

You are setting the from header to be the address posted in the form, and the to header to be your email address. Should be reversed if you are trying to send an email to them.


$from = "<".stripslashes($_POST['email']).">";

If indeed you want the email to appear to come from the address listed in the form, you can't in general do that. You can't send email on behalf of another use (your SMTP server is likely to reject it these days). This is to prevent pfishing attacks (FROM: Someone@ThatYouKnow.com, SUBJECT: What is that password again?).

Send it from an email address that you control. Include the email address from the form as part of the body of the email.

Post Status

Asked in February 2016
Viewed 3,355 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life