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.
Related
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 :)
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);
I have some code that has worked for me in the past, but isn't anymore, for some reason I don't understand. I'm pretty sure the problem isn't in the code itself, since 1) I haven't changed anything, and 2) it's worked for me in the past. I am using XAMPP and PHP.
My webpage allows a user to fill out a contact form and send an email through PHP. It seems to execute successfully, since it takes the user to "thankyou.html" as a result. To troubleshoot the issue, I have 1) cleared my browser's cache and 2) checked my spam folder in Gmail.
But I still can't find my email, and don't know why. I'm not familiar with how SMTP works; if the problem has to do with that, then I would appreciate an explanation.
Here is the code:
<?php
$field_first_name = $_POST['cf_first_name'];
$field_last_name = $_POST['cf_last_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$field_reference = $_POST['cf_reference'];
$mail_to = 'myself#gmail.com';
$subject = 'Message from a website visitor '.$field_first_name.' '.$field_last_name;
$body_message = 'From: '.$field_first_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message."\n";
$body_message .= 'Reference: '.$field_reference;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
//alert('Thank you for the message. We will contact you shortly.');
window.location = 'thankyou.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to someemail#gmail.com');
window.location = 'home.php';
</script>
<?php
}
?>
Any input is much appreciated!
At least AOL automatically drops all emails sent by PHP's internal mail (I don't know how they detect it, it simply will not show up in the inbox).
A solution is to use a email library like PHPMailer and send your emails via a real SMTP server.
Edit: Does your local machine have a dynamic or fixed IP address? Almost every serious SMTP server does reject emails sent by dynamic IP addresses.
I am using this: (in my website and not in XAMPP)
$from = "mail#mail.de";
$to = "mail#mail.de";
$subject = "subject";
$mailtext = "blablabla";
mail($to, $subject, $mailtext, "From: $from ");
And it's working!
But I tried it with XAMPP as well and nothing happens :(
So I don't know how to use mail() with XAMPP.
As of Nov 2022
Anyone sending emails to Gmail accounts, including personal accounts ending in #gmail.com or googlemail.com, and Google Workspace accounts for work or school must set up either SPF or DKIM to avoid Gmail blocking or marking your emails as spam.
https://support.google.com/a/answer/33786
I want to send the user an activation link after they registered an account. when I put this http://www.homeloan.com.sg in the $message I didn't receive the email, but when I remove the .sg and put http://www.homeloan.com it works. There's no error message, so I really don't know what's my mistake. Please help
here are my codes:
$id = mysql_insert_id();
$to = 'myemail#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account-> http://www.homeloan.com.sg/rates/activate?id='.$id.'';
$headers = "From: Homeloan Singapore" . "\r\n" . "Reply-To: enquiry#homeloan.com.sg";
mail($to,$subject,$message,$headers, '-f enquiry#homeloan.com.sg');
Make sure if your site have a form to fill, then fill the form correctly by assembling the input tag in the corresponded variable.
Try concatenating 'the email' to the variables ($...) with (.) or "...".
I really don't know what's my mistake
There is no mistake. I tried this code:
<?php
$id = 1;
$to = 'my_email#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account-> http://www.homeloan.com.sg/rates/activate?id='.$id;
$headers = "From: Homeloan Singapore" . "\r\n" . "Reply-To: enquiry#homeloan.com.sg";
mail($to,$subject,$message,$headers, '-f enquiry#homeloan.com.sg');
It arrived in the mailbox. Maybe, for your account it was put into spam folder?
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.