PHP E-Mail Form Sender Name Instead of E-Mail

PHP E-mail Form Sender Name Instead Of E-mail?

Right after your 4 lines that say $email_message .= ... add a line:

$email_from = $full_name.'<'.$email_from.'>';

Change the sender name php mail instead of sitename@hostname.com

You only use $from in your Reply-To header. If you want it to be in the From header, you need to set it in the From header.

Put something like this before your mail() command:

$headers .= 'From: ' . $from . "\r\n";

PHP send mail show name instead of an email

from: Jon Jones <Jon@Jones.com>

PHP mail not showing senders email in from header frfom HTML form

You can't send from a gmail address unless you're sending through gmail's servers, which essentially means you can't use PHP's mail() function to do it. You may be able to try, but your messages will be marked as forgeries.

To set the envelope sender with the mail function, you need to use a -f parameter in the $additional_params parameter in the mail function.

Your script is vulnerable to header injection attacks, and it is also exploitable for cross-site scripting.

To avoid the forgery issue, I recommend sending directly through gmail, which mean you need to use SMTP, and the easiest way to do that is to use PHPMailer that you tagged this question with. Base your code on the examples provided with it.

Contact form sending emails without name, email and message

Your HTML should look like:

<form action="form_process.php" class="contact_form" method="post">
<ul>
<li>
<label for="name">name:</label>
<input type="text" name="name" required />
</li>
<li>
<label for="email">email:</label>
<input type="email" name="email" required />
</li>
<li>
<label for="message">message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Enviar</button>
</li>
</ul>
</form>

Your PHP should look like:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "mmechenique@gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
$headers = "From: Enter something here < email@mail.com >\r\n";
$headers .= "X-Sender: Enter something here < email@mail.com >\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\r\n"; // Urgent message!
$headers .= "Return-Path: email@mail.com\r\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";

mail ($to, $subject, $message, $headers);
echo "Tu mensaje ha sido enviado, muchas gracias!";

?>

I shouldn't be giving out the answer so easily because you should have done your research before posting your question but what the hell. Now you know for next time to do SOME research before posting your question.

EDIT:

<?php
$headers = "From: Enter your name < myemail@mail.com >\n"; //If you are the one sending the email enter your name here
OR
$headers = "From: ".$name." < ".$email." >\n"; // If you are the one the email is being sent to then try this header

$headers .= "X-Sender: Enter your name < myemail@mail.com >\n"; //Same logic applies for this guy
OR
$headers .= "X-Sender: ".$name." < ".$email." >\n"; //Same logic applies for this guy
?>

Mailto form does not include sender's email

Right now you're putting the $name variable in the field where you should be putting the sender's email address ($email). You can use both, but unfortunately you need to hack them together, since the PHP mail function doesn't do it for you.

You can add both like this:

mail($to, $subject, $comments, 'From: "' . $name . '" <' . $email . '>')

Note, you need to include double-quote characters inside the string, which can get a little dicey but you can use ' to avoid needing to get more complicated.

If $name is "Bob" and $email is "bob@test.test", then all together this should look like: 'From: "Bob" <bob@test.test>'. See also, this question on how to format email headers



Related Topics



Leave a reply



Submit