Simple-PHP-Contact-Form icon indicating copy to clipboard operation
Simple-PHP-Contact-Form copied to clipboard

From address is same as sender address

Open dannyboy opened this issue 7 years ago • 10 comments

Confused. Why is the from address set to the sender address?

Shouldn't this:

$header  .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;
$header  .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

be more like this:

$header  .= 'From: ' . $this->from . PHP_EOL;
$header  .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

Sorry if i've missed something.

dannyboy avatar Jun 14 '18 10:06 dannyboy

Hey this is my first time working with php and i'm trying to use it in a contact form page to send the website owner a email, i'm not sure what the issue is but it wont send the the the email doesn't get sent to the website owner if you can give any advice please let me know thanks 👍

BigBird420 avatar Aug 30 '18 15:08 BigBird420

I can send you my snippet later today if you need to see it

BigBird420 avatar Aug 30 '18 15:08 BigBird420

@BigBird420 What error have you received? If you haven't received like me, I just change the code like above and started to work.

aftoledo avatar Aug 30 '18 15:08 aftoledo

@aftoledo there are no error messages the site seems to be running the php file fine but it doesn’t send a email to the owners email account

BigBird420 avatar Aug 30 '18 16:08 BigBird420

@BigBird420

If your problem is like mine, just change it: $header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL; $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

to something like this: $header .= 'From: ' . $this->from . PHP_EOL; $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

aftoledo avatar Aug 30 '18 16:08 aftoledo

@aftoledo when I get home I’ll share my snippet looks different from yours

BigBird420 avatar Aug 30 '18 16:08 BigBird420

@aftoledo <?php $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['message'];

$email_form = '[email protected]';

$email_subject = "New Form Submission";

$email_body = "User Name: $name.\n".
				"User Email: $visitor_email.\n".
				 	"User Message: $message.\n";

$to = "[email protected]";

$headers = "form: $email_form \r\n";

$headers .= "Reply-To: $visitor_email \r\n";

mail($to,$email_subject,$email_body,$headers);

header("Location: index.html");

?>

BigBird420 avatar Sep 01 '18 18:09 BigBird420

I don't know if it matters, but try to change single to double cotes here: $email_form = '[email protected]';

aftoledo avatar Sep 02 '18 15:09 aftoledo

double and single quotes: https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php

aftoledo avatar Sep 02 '18 16:09 aftoledo

hey it didnt end up working i just went back and restarted the form by using formspree and javascript thanks though

BigBird420 avatar Sep 09 '18 16:09 BigBird420