php/ email/ html-email/ mail-form/ formmail

I refer to this page. https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form

i want mailheader "name"

but this php code is

 <?php // configure $from = 'Demo contact form <demo@domain.com>'; $sendTo = 'Demo contact form <demo@domain.com>'; $subject = 'New message from contact form'; $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in the email $okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!'; $errorMessage = 'There was an error while submitting the form. Please try again later'; // let's do the sending try { $emailText = "You have new message from contact form\\n=============================\\n"; foreach ($_POST as $key => $value) { if (isset($fields[$key])) { $emailText .= "$fields[$key]: $value\\n"; } } $headers = array('Content-Type: text/plain; charset="UTF-8";', 'From: ' . $from, 'Reply-To: ' . $from, 'Return-Path: ' . $from, ); mail($sendTo, $subject, $emailText, implode("\\n", $headers)); $responseArray = array('type' => 'success', 'message' => $okMessage); } catch (\\Exception $e) { $responseArray = array('type' => 'danger', 'message' => $errorMessage); } if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $encoded = json_encode($responseArray); header('Content-Type: application/json'); echo $encoded; } else { echo $responseArray['message']; } 

so i tried

$sendTo = 'Demo contact form '; => my mail.

$from = 'Demo contact form '; => $name <'$email'> but the result is "nobody"

So i tried again.

  $headers = array('Content-Type: text/plain; charset="UTF-8";', 'From: ' . $from, 'Reply-To: ' . $from, 'Return-Path: ' . $from, ); 

=>

  $headers = array('Content-Type: text/plain; charset="UTF-8";', 'From: ' . $from<$email>, 'Reply-To: ' . $from, 'Return-Path: ' . $from, ); 

But it failed...

what should i do?

i tried

From: $FromName and

$headers = "From: $from_user \\r\\n". and

$headers .= 'From: "'. $from . '" <' . $Email . '>' . "\\r\\n"; etc...

This worked for me

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));

$from = "$name<$email_address>";

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Not receiving email from PHP mail() contact form PHP Form - bcc mail not sent from email form PHP mail not showing senders email in from header frfom HTML form Unable to send data from HTML form to email using PHP mail() How to get the email senders name from the contact form - Laravel Mail PHP mail form - email header Email not sending in form Bootstrap send email from bootstrap framework My error in this is i got a message is Mail sent successfully but i didn't receive any mail jQuery AJAX form using mail() PHP script sends email, but POST data from HTML form is undefined Bootstrap form with modal, validator and email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM