I'm using BlueHost and I can't seem to get my email form to work. This is the PHP:
$to = "test#email.com";
$subject = "test";
$message = "test message";
$from = $_POST['cf_email'];
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo $headers;
This doesn't seem to send the email. However, if I add ANY string in front of the email, then it works. e.g.:
$from = "zz".$_POST['cf_email'];
Can anyone tell me what I'm doing wrong? Thanks.
You cannot use any personal email ($_POST['cf_email']) in the 'From' header.
Also you have to add 'reply-to'.
Please check below thread for more info.
problem with php mail 'From' header
Related
Hallo I've got a problem with sending html E-mails with a dyanamic Link via PHP.
That is my PHP Code:
$empfaenger = $_POST['email'];
$test = sha1($_POST['email']);
$betreff = "Test Mail";
$from = "From: Peter <tets#gmail.com>\n";
$from .= "Reply-To: test16#gmail.com\n";
$from .= "Content-Type: text/html\n";
$text = "Please click <p><a href='http://defaultpage/default.php?res=".$test."'>here</a></p>.";
mail($empfaenger, $betreff, $text, $from);
In the mail Log all looks normal like the mail is sended, but I didn't receive one. In PHP error Log also nothing. If I set $test to a specified string it's working as expected, but not with the dyanamic variable $test. I hope that someone can help me becuse I can't get rid of this problem.
I am new to php and stackoverflow and I am trying to figure out a simple website contact form. I have the form and email functioning properly, but I have one nagging issue I can't figure out.
When the email is sent, the from email says myusername#p3pxxxxxx.com which is my server. When I direct the email to my domain based email account, they don't get to my inbox, I bet the spam filters are stopping the odd email address. So I tried sending it to my gmail inbox, which worked, but I don't check that email regularly. I'd rather have it go to my domain based email account.
So, I am looking for a way to edit the 'from' email address. Instead of the user/server I would like it to use a real email address, mine or the person that sent it would be even better. Here are a couple of attempts and what I currently have, none of which worked.
Couple of Attempts:
Attempted to pull the email address entered my sender.
//$mailheader = "From: ".$_POST["email"]."\r\n";
//$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
This was another attempt.
//$mailheaders = "From: webmaster#example.com\r\nReply-To: webmaster#example.com";
What I currently have:
<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];
$to = "myemailaddress#gmail.com";
$subject = "Contact Message from Website";
$mailheaders = "From: webmaster#example.com\r\nReply-To: webmaster#example.com";
$message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
if ($security=="10") {
mail($to,$subject,$message,$mailheaders);
header("Location:contact.php?s=1");
}
else {
header("Location:contact.php?s=2");
}
?>
Followed the suggestion. Last attempt still didn't work...
<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];
$to = "mail#example.com";
$subject = "Contact Message from Website";
$message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
$mailheaders = "From: webmaster#example.com\r\nReply-To: website#example.com";
if ($security=="10") {
mail($to,$subject,$message,$mailheaders);
header("Location:contact.php?s=1");
}
else {
header("Location:contact.php?s=2");
}
?>
Alastair's correction should work.
When you were calling the mail function, you weren't passing in the variables in the proper order.
How you were calling it: mail($to, $subject, $mailheaders, $message)
But the actual order is: mail($to, $subject, $message, $mailheaders)
Notice how I switch $message and $mailheaders
It's a thing you can check on PHP's documentation, such as:
http://us3.php.net/manual/en/function.mail.php
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
I have a simple php email script where I wish to include an image at the bottom. When I add the image tags like below the email just shows <img src="http://domain.com/images/logo.png" /> instead of the actual image. Any ideas why?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: info#domain.com\n";
$usermessage =
"
Thank you for joining our mailing list.
We hope to see you very soon!
Address 1
Address 2
<img src=\"http://domain.com/images/logo.png\" />
";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
$fh = fopen("email.xml", "a");
fwrite($fh, "$email\r\n");
fclose($fh);
?>
You're not passing the Content-Type header with the right message. $headers does contain the right header, but it is sent with a plain text message, whereas $userheaders does not contain the Content-Type header, but the message associated with it does contain some HTML
Replace
$userheaders = "From: info#domain.com\n";
with
$userheaders = "From: info#domain.com\r\n";
$userheaders = "Content-type: text/html\r\n";
and it should work perfectly
This is a word press plugin but if you delete everything BUT the XmailBaby class it should work for you nicely.
That code is a nice piece of work that sends emails very good.
It is just a basic version but it should be enough for you.
Take a look through the code, you might find it interesting.
http://plugins.svn.wordpress.org/xmail-the-right-way/trunk/xmail.php
You need to specify html headers. Rather than do this yourself, you can use a well-established method that supports sending HTML emails, such as PHPMailer:
http://phpmailer.worxware.com/
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?
Even this must have been be asked many times, I will ask again since I cannot get it to work.
I am using php mail($to, $subject, $message, "From: $mysite<$myemail>\nX-Mailer:PHP/" .phpversion()); to send email to a single recipient.
Now I need to sent it to more than one recipients. I know that normaly I could do:
$to = "emailA#here.com,emailB#there.com";
But I need the one of the recipients to be the user that fills in the form e.g.:
//get all form details
$email = $_POST['email'];
$to = "$email,emailB#there.com";
The above ($to) I don't know if it is correct or not but is not working for me...
If I leave only the $to = "$email"; it gets send to $email (meaning that my rest of the code is ok).
Any suggestion on what is or may be wrong here?
Thank you.
Add a CC to your header.
$header ="From: $mysite<$myemail>" . PHP_EOL;
$header .= 'CC: emailB#there.com' . PHP_EOL;
//Rest of headers here