Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Make Contact Form from Input Email WordPress

  • SOLVED

I have a contact form which I would like to keep the same for the most part, the relevant code can be found in the first link.

When emails are received from this contact form, the email is sent from [email protected]. However, this contact form has a place for the user to input their email address. How do I setup this contact form so that when emails are received they appear to come from whatever email address input by the sender of the form?

$from = "FirmFlip";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";

if(@mail($to,$subject,$message,$headers))


http://snippi.com/s/okibmoo
http://snippi.com/s/zyvnwe1

Answers (7)

2014-01-06

Balanean Corneliu answers:

$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";


Balanean Corneliu comments:

Full code :


$from = "FirmFlip";
$headers .= "From: <$from> \r\n";
$headers .= "Reply-To: <$from> \r\n";
$headers .= "Return-Path: <$from>\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";

if(@mail($to,$subject,$message,$headers))


siouxfan45 comments:

This code did not send the email from the email input by the user.

2014-01-06

Nirmal answers:

Use the <strong>$email</strong> which is nothing but the collected email id of the user.

$from = "FirmFlip";
$headers = "From:" . $email . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
if(@mail($to,$subject,$message,$headers))

2014-01-06

Arnav Joy answers:

try this

<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: FirmFlip ".$email;
$headers[] = "X-Mailer: PHP/".phpversion();


if(@mail($to,$subject,$message,$headers))



?>


siouxfan45 comments:

When I try this code, it says "Error, please try again!" when I hit send.


Arnav Joy comments:

try this


<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: FirmFlip ".$email;
$headers[] = "X-Mailer: PHP/".phpversion();


if(@mail($to,$subject,$message,implode("\r\n", $headers)))



?>

2014-01-06

Just Me answers:

replace

$from = "FirmFlip";


with

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

2014-01-07

Ryan S answers:

Update the whole code to this.


<?php

// Get values from form
$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$message=$_POST['message'];

$to = "[email protected]";
$subject = "Potential Client Lead";
$message = " Name: " . $name . "\r\n Phone: " . $phone . "\r\n Email: " . $email . "\r\n Message: " . $message;

$from = $name; // sender name
$from_email = $email; // sender email address

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: FirmFlip <'. $to .'>' . "\r\n";
$headers .= 'From: '. $from .' <'. $from_email .'>' . "\r\n";

// send mail
$mail = mail( $to, $subject, $message, $headers );

if( $mail )
echo "<script>document.location.href='/thanks/';</script>";
else
echo "Error! Please try again.";

2014-01-07

Fahad Murtaza answers:

By the way, some shared hosts don't allow this way of php mail. The php mail should originate from a server which has access to the email address ( it should be hosted on the same server).

I had similar issue with hostmonster many times.

2014-01-07

Hariprasad Vijayan answers:

Hello,

I think this is hosting server issue. Some server doesn't allow third party email address for from email in mail() function and need use an email address that created in the same domain as from email in mail() function. Contact provider for details.