Change email address that sends confirmation email (PHP) - 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.

Related

Php Register Email Verification

I've put together a registration form for my website which will use an email verification. I would like to select a default mailbox to send outgoing emails. How do i specify which mail box on my webhosting the outgoing email will be sent from?
if($result2){
$to = $email;
$subject = "Immo Registration Confirmation - $username";
$header = "Immo: Confirmation from Immo";
$message = "Thank you for registering at Immo Please click the link below to verify and activate your account. <br>";
$message .= "http://www.test.com/confirm.php?passkey=$confirmcode";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else
{
echo "Cannot send Confirmation link to your e-mail address";
}
}
The email system is working, I have tested it however the email address that it's coming from is random spam and i would like to assign a certain mailbox for registration. How can this be achieved?
You need to set the 'From' header correctly. something like below taken from the docs http://php.net/manual/en/function.mail.php
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
You can define the sender email by adding this to your $header variable.
$header .= 'From: from#mail.com \r\n';

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 :)

Contact Form reply address

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);

Multiple and Separate Mail Functions PHP

Is my $headers and or second mail() function incorrect or improper? My page has a form that when you fill out will send an email to the recipient, then a second one to via a text message (many carriers has a text to email feature). When I submitted the form the first mail() function works, but the second one doesn't. Any ideas? Also, I'm doing this because I want it to send an email and a text message (I thought this was a great idea) so that the recipient is notified that there's an email that needs his/her attention.
Here's what I mean.
// HTML FORM here, collects just name, email, subject line, message
// When the form is submitted it does this...
$to = "recepient#email.com";
$to_sms = "recepienttextnumber#tmomail.net";
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING)." - FORM";
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-type:text/html;charset=iso-8859-1' . "\r\n" .
'From: noreply#email.com' . "\r\n" .
'Reply-To: info#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "
<html>
<p>This is an automatic email notification. <strong>Please do not reply to this email</strong></p>
<p>You received a message from ". $name . " that needs your attention ASAP.!</p>
<p>Client name: ".$name."<br />
Client phone: ".$phone."<br />
Email: ".$email."<br />
About: ".$_POST['subject']."<br />
Message: ".$message."</p>
</html>";
$body_sms = "Great news! ".$name." has contacted you via the FORM. Check your email now.";
// Send Email & Text Notification
//Here sends out the form via email
mail($to, $subject, $body, $headers);
//alternatively a second message is sent to another
mail($to_sms, $subject, $body_sms, "From: FORM");
//Echos a thank you.
I suggest you make a copy of your $headers and name it $headers2 and use
mail($to, $subject, $body_sms, $headers2);
that may be the problem.

PHP Mail Don't Show "To" in "To" Header

I want to make an email forwarder similar to cPanel's, where I have a database of email addresses, and where they should forward to, and I set a catch-all to pipe to my script.
I have completed this script, however, I would like to make the "To:" field in the header show the address it was sent to, rather than who is was being delivered to. For example, the email was sent to user001#mydomain.com, and the script forwards it to me#gmail.com. How can I make PHP send mail to me#gmail.com, but still show user001#mydomain.com in the headers, like cPanel does?
You can use the headers of the mail function:
$to = 'me#gmail.com';
$subject = 'Testing';
$message = 'This is a test';
$headers .= 'To: User001 <user001#mydomain.com>, User002 <user002#mydomain.com>' . "\r\n";
$headers .= 'From: My Email Script <me#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);

Categories