Below is the Webform PHP code I used for e-mail function. After I click the SUBMIT button in the form, I am successfully getting redirected to the thankyou.html page but I don't get any e-mail to my e-mail account. Kind help is deeply appreciated.
PHP Code:
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
mail('myemail#email.com', 'Subject Line', $emailbody);
header('location: thankyou.html');
} else {
header('location: index.html');
}
?>
You may be missing the "From" field in the $additional_headers argument. Try
$headers = 'From: myemail#email.com';
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
It might be a problem with your host.
I think due to the email spams that #email.com got from your host it may be now in the blacklist.
This means you have to contact your host about this problem and tell them to talk with #email.com to remove your host from the blacklist.
I had this problem a while ago on 000webhost.com and they told me i can't send emails to an yahoo.com account because yahoo.com added the 000webhost.com on the blacklist because users spammed the Yahoo servers.
It's likely that your server, or one along the route, is refusing to deliver the mail because it has no From: address. You can add one using the headers parameter for mail():
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
// Add extra headers here
$headers = "From:address#examle.com"
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
header('location: index.html');
} else {
header('location: about-us.html');
}
You should check any user-suplied input to ensure it doesn't try to subvert your mail function by adding headers of its own. Check for text like To:, Cc: or Bcc:.
Most ISPs will refuse to deliver email unless it comes from a domain registered with them. Sometimes the from address must exist on the server generating the mail.
Note that there are other reasons why mail might not be delivered: bad addressing and spam filters to name but two.
I found the answer. I just changed $emailbody into $message and it is working fine now. I am not sure that using $emailbody instead of $message was the issue but it is working fine now.
Thank you all.
First check your hosting server is that providing mail functionality for this you just write
echo phpinfo();
you need to check the mail function enable or not
Related
I tested this:
<?php
$to = "recipient#example.com";
$subject = "Hi!";
$server = $_SERVER['HTTP_HOST'];
$body = "From: ". $server. "<br>";
$body .= "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
This will never send emails to me although the feedback "successfully" is displayed.
The code will work (email actually sent) however if I removed the inclusion of
$server = $_SERVER['HTTP_HOST'];
in the email body.
Very weird, it doesn't make sense ?
This is just a PHP page. I call this page from a browser !! Please try ...
UPDATE!! okay, Instead of using $_SERVER['HTTP_HOST'], I use a string "user.server.com" directly. AND, it did not work !!
But, when I modified a string a bit, like "user.server.com.us", it works !!
So basically, the mail server filler its own reference to its domain, not sure why its doing this...
Some spam servers grade your message as 'spammy' for urls in the body. Unfortunately you'll be hard-pressed to find a more specific error message with mail() unless you have access to the sender and recipient's mail server logs. Give SwiftMailer or another PHP Mailing library for better support.
When using mail() function you are required to specify 'From' header. Please refer to this documentation page, look for 'additional_headers' parameter's Notes section.
So your mail() call will look like this:
mail($to, $subject, $body, 'From: some.guy#example.com');
Of course you don't receive it because there these days all major webmails use anti spam filters and probably your message is detected as a spam.
The solution is to specify exactly your email for $from variable, if you don't specify your real email your message is detected as spam.
I have this mail script on my page: mail('myadress#server.com', 'New client added by user', 'test message');
but I do not receive anything! (of course I added my real adress). I tried it with 2 different adresses, looked in my spam folder, etc... just nothing. but the script executes just fine.
Is there any log I can view or invoke to see exactly what happened?
thank you for your help!
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
try this it will going to work for u ....
1) Check the return value from the mail() call:
$status = mail(...);
if (!$status) {
die("Mail failed");
}
If this fails, then PHP cannot even get the mail out the front door, and you'll have to figure out why - e.g. are you on a Windows box and haven't configured the mail options in php.ini?
2) Check your mail server's logs. Most Unix/Linux systems have a local mail server (the MTA) which will accept the mail from PHP. If it's misconfigured or having trouble, it may still accept the mail from PHP but then leave the mail to rot in a queue.
Perhaps your server's been placed on spam blackhole lists and it simply cannot deliver mail anywhere, which means you've probably got all of your test mails stuck in an outgoing queue that can't go anywhere.
Had to add the header "from" and use an email adress created on the server.
http://www.raymondselda.com/php-contact-form-with-jquery-validation/
I'm trying a few different contact forms including the one above.
I have it running on this page: http://themeforward.com/demo2/features/contact-form/
The problem is this form does not successfully send e-mails to the address in the code (finished code can be found here: http://www.raymondselda.com/php-contact-form-with-jquery-validation/ )
Does anybody know what the problem may be?
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'youremail#email.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
Many reasons:
Mail isn't configured properly on your server. mail() will return a boolean FALSE if it can't hand off the email to an SMTP server. You're not checking for that condition
The SMTP server isn't configured properly to allow you to send through it
The receiver server has your sending server blacklisted
The email is treated as spam and is getting trashed
First place to start looking is mail()'s return value. Then go look at your SMTP server's log to see what happens to the email (if) once PHP handed it over. The SMTP server's log will also say if the receiving server bounced/refused it.
If it's getting silently thrown in a spam folder on the receiver server, there'll be NO evidence of this on your end, and you'll have to investigate further on the receiving end.
Email is a complicated business with many many invididual steps where each one has to work right. Any glitches anywhere along the line and the email is probably gone. You have to investigate what happens at EACH of these stages to figure out why something isn't being delivered.
I am trying to send text messages to my phone from my server using php. I recently configured the server to send email, which it does (verified). It, however, goes into my spam box. When I try to send a message via sms I do not receive anything.
This is the script I am using:
$to = "myemailaddress#gmail.com";
$subject = "testing";
$body = "";
$headers = 'From: testemailaddress#gmail.com';
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
The address that I am using for sms is myphonenumber#txt.att.net in the 'To' field.
I am going to go out on a limb here and say this is a authentication issue, maybe.
Is there anything I need to configure further? (i.e. php.ini)
Most email providers/servers today rely heavily on spam filtering / dnsbl. Your webserver is not a know mail server, and you probably did not set up SPF or anything.
An approach to avoid all those issues would be to utilize a Google Mail address (or any other providers). And instead of the PHP mail function use something more complex like Swiftmailer, which generates Mail headers that are less commonly autoclassified as spam.
See also: Using php's swiftmailer with gmail
I'm currently trying to get links working in emails sent via the PHP mail function. Here is my code - I've also included some things I've tried (commented out along with notes):
$to = "test#testing.com";
$subject = "Testing email";
//$body = '<strong>This is strong text</strong>'; <-- Works
//and the text is correctly emphasised.
//$body = 'Link Test'; <-- Works
//but without http:// at the start makes the link relative to the server root
//$body = "<a href='http://www.yahoo.com'>Link Test</a>"; <-- Does not work
//$body = "Link Test"; <-- Does not work
$body = 'Link Test'; //<-- Does not work
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Steven Parler <". $to . ">\r\n";
$headers .= "X-Mailer: PHP/".phpversion() . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
As can be seen html is working without links, and links also work providing I don't include "http://" in the link itself. If I do include the "http://" then no email is received / sent at all (I'm unsure which as the mail() command returns true to say it was sent).
I'm not really sure why this isn't working. Could it be some setting that needs changing on my webhost's server? I'm on windows shared hosting.
Thanks in advance for any advice anyone can give me - been pulling my hair out over this lol. :)
Don't build MIME messages by hand. It's just too painful and fragile. Use something like PHPMailer or SwiftMailer to do it for your automatically. You provide the HTML, they'll provide the appropriate headers
I completely agree with #Marc B.
Here are a couple more options: XPertMailer, Zend_Mail, Rmail, HTML MIME MAIL
I've worked with all of these but since I'm working mostly with the Zend Framework I'm lately using Zend_Mail.
Having said that, your hosting provider might be blocking your emails because they might think it's SPAM. Try generating valid html markup that passes validation and see if that helps.
That's very odd behaviour, I'd expect the last 2 to work perfectly. I tried this out on my server, and mail($email, $subject, $body, $headers); worked perfectly with a $body of
text text text: \n http://website.com.
Perhaps it's a setting somewhere? If you're using awardspace, they require a from header to be used, and the mail sent from an e-mail registered with them. Other hosts might have a similar procedure.
Thanks for all the responses. I finally got around it by using the SMTP feature of Swiftmailer which correctly created the email with links.
Out of interest I tried the code I used in my original post again... but this time I used a random web address (http://www.trustedreviews.com). The email arrived... I then tried a lot of other web addresses - google.com, hotmail, yahoo.co.uk etc and they all arrived. Changed it back to (http://www.yahoo.com) and lo and behold the message did not arrive again. So it seems out of the millions of web URL's there are I chose the one that my webhost has decided to block lol...
That said the yahoo link does arrive ok using the smtp function of swift mail; it's only with the php mail function it doesn't seem to work. I guess I'll contact them and ask why it's blocked. I'll most likely stick with using the smtp method as at least it seems like it bypasses any restrictions.
Thanks again for everyone's time and help :)