Contact Form reply address - php

When somebody send me a message on my websites contact form, I click the reply button to reply.
I then receive a response that the email was not delivered / failed.
Well, its because the gmail email wants to respond to the server email, instead of the email address that was entered into the Contact Form on my website.
Does anybody know how to fix this?
Here is the PHP script for my contact form:
<?php
$mailTo = 'emailaddress#gmail.com';
$name = htmlspecialchars($_POST['cform_name']);
$mailFrom = htmlspecialchars($_POST['cform_email']);
$subject = 'Message from your website';
$message_text = htmlspecialchars($_POST['cform_message']);
$message = 'From: '.$name.'; Email: '.$mailFrom.' ; Message: '.$message_text;
mail($mailTo, $subject, $message);
?>

Use this:
mail($mailTo, $subject, $message, 'Reply-To: '.$mailFrom);

Related

send private copy of autoresponder mail

I have some php here that works great. I want a mail to be sent to the user who submits a form and I also want a copy of that mail sent to myself but I don't want my email address to be made available to the user.
Here's the php I'm using to govern the mail sending ...
$to = 'xxxx#xxxx.com' . ', ';
$to .= $email;
$subject = 'xxxx';
$message = "Thank you for submitting the form.";
$headers = "From: xxxx#xxxx.com\r\nReply-To: xxxx#xxxx.com";
$mail_sent = #mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
When the code is parsed emails are duly sent to both the users submitted email ($email) and the address I enter in the first $to variable however the user can see the email address I enter as another recipient when they receive the email. Anyone know how I can get around this? Any help will be much appreciated. Thanks.
Use a BCC header instead of an additional To in your $headers string. It stands for "Blind Carbon Copy", and instructs the mail server to duplicate the mail to extra recipients, but remove that header from the original copy, so the main recipients can't know it was there.

php email script for just email address

Im new to this PHP stuff so please excuse my ignorance
Im after having just one input text box in my flash website where a person just enters there email address and at the click of a button it sends an email to me to a pre defined email address with a predefined subject heading and the email address that was entered in the body of the email
Anyone know of any links or can give some help
all the ones i have found want names email subject message and so on
Any help is appreciated
Mark
EDIT
ok I have the following
In flash I have an input text converted to a movieclip called "addy". Inside the movie clip which has the inputbox which has the variable name "emailaddy"
A Button called "email"
The code i Have running when "email" is clicked is
on (release) {
form.loadVariables("email.php", "POST");
}
the email.php script is as follows
<?php
$sendTo = "mark#here.co.uk";
$subject = "Subscribe to Website";
$headers = "From: Website";
$headers .= "<" . $_POST["addy"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["addy"] . "\r\n";
$headers .= "Return-Path: " . $_POST["addy"];
$message = "Please Subscribe me to Website";
mail(recipient, subject, message, other headers);
mail($sendTo, $subject, $message, $headers);
?>
when I click the button nothing happens
what im after is when the button is clicked for and email to be sent in the following format
To: "mark#here.co.uk"
From: email address specified in text field "addy"
Subject: "Subscribe to Website";
body: "Please subscribe me to Website"
Your help is greatly appreciated
mark
The following code might help:
<?php
$user_mail=$_POST["mail"]; //or $user_mail=$_GET["mail"]; Set to your convenience!
$to_mail="abcde#xyz.com"; //Change to your email address
$message="New user's Email: ".$user_mail; //Change to your requirements
$subject="New user registered"; //Change to your preferred subject
$from="registration#yourwebsite.com"; //Change to your website mail id
mail($to_mail,$subject,$message,"From: $from\n");
To know more about the mail function, please see the documentation.
Well in depth you can do like this
<?php
if($_POST){
$userEmail = $_POST0["emailaddy"]; // textbox variable name comes here
$to = 'abc#xyz.com'; //write down here your email
$subject = 'Subscribe to website'; // your subject goes here
$message = 'Please Subscribe me to Website'; // Mail body message
$headers = 'From: ' . $userEmail . "\r\n" .
'Reply-To: ' . $userEmail . "\r\n" .
'Return-Path: ' . $userEmail; //can send x-Mailer also
mail($to, $subject, $message, $headers);
}else{
echo "Invalid Request";
return false;
}
Don't forget to check first $_POST is happened or not. No need to send Return-path instead of this use x-Mailer which sound good for other mail service providers.
To know more about this read documentation here.
If you want to connect to an SMTP server ,like Postfix or gmail there is a neat php library called PhpMailer.
It is well documentated, so you should be good to go by googleing it :)

Form-mailer Inbox-display issue

The line of code below is part of the form-mailer that processes the form on my Website. Whenever I receive an E-mail from the form, I can't see the name of the sender until I open the email because it displays(Inbox display) just the E-mail address and the Subject. How do I get it to display the Name and the Subject(Inbox display), so that I'll know the sender before I open it. I'd also like it to be reply-ready, So it replies to the sender's email When I Click on reply.
$message = "\n$fname submitted the following message:\n\n$message\n\n$fname's contact details are as follows:\n\nFirst Name: $fname\nLast Name: $lname\nPhone Number: $phone\nEmail Address: $email\n";
mail($mailto, "$subject", $message, "From: $email");
?>
mail($mailto, $subject, $message, "From: Person's Name<$email>" );
It can be solved in this way also:
A) In Your Code:
$mail->FromName = "Name Of Mailer";
B) In Phpmailer:
public $FromName = 'Terasoft'; //Root User
Hope this May work For you.

Sending Email Twice from PHP

I'm doing this simple testing on creating form where I want the form to send email twice:
to my email address, to notify me if somebody has reached me
to the sender's email address to notify him/her that the contact has been sent to me.
problem is, I could send the first email, but I couldn't send the second one. I thought this should be easy. I may miss a line or two here. Here's the code:
<?php
$field_email = $_POST['email'];
$mail_to = 'myemail#mydomain.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message .= 'E-mail: '.$field_email."\n";
$headers = 'From: '.$field_email."\r\n";
$headersTo = 'From: '.$mail_to."\r\n";
$body_messageTo = 'Thank you for your interest';
$subjectTo = 'Thank You from Gaban';
$mail_status = mail($mail_to, $subject, $body_message, $headers);
$autoreply = mail($field_email, $subjectTo, $body_messageTo, $headersTo);
?>
the $field_email should take data directly from the "email" form from the HTML code.
Unless $_POST['email'] contains an invalid email address, I can't see anything wrong with it. I'd say the problem is most likely to be found in the mailserver processing the mailbox where the second email is sent to.

Change email address that sends confirmation email (PHP)

I have a registration page on a site I'm working on. When the person registers for an account it sends an email to the registrants email address with a confirmation link to activate the persons account. The problem is that the "from" email address the registrant receives the email from is: myhostingaccountusername#myhostingprovider###.com.
I want to be able to have the email be: no-reply#mydomain.com.
I'm using PHP and Mysql along with html for the site.
here is my code for sending the email.
// Send the email:
$body = "Thank you for registering at My site. To activate your account, please click on this link:\n\n";
$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$abc";
mail($trimmed['email'], 'Registration Confirmation', $body, 'From: noreply#mysite.com');
How do I do this?
When sending the e-mail to your "registrant" you should set the headers of the mail function in PHP to contain "From" field
for example :
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: no-reply#example.com' . "\r\n" .
'Reply-To: me#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Have you set the From: header for the e-mail?
See http://php.net/manual/en/function.mail.php, example #2.

Categories