"No encryption" error when using PHP "mail" function - php

Building a site that currently doesn't have "https".
Trying to test out a login scheme that sends a validation email.
Tried out PHP's mail() function, and it worked, except that the email went into Spam in the receiver's Gmail. (This is my first time playing with mail()).
The Question: Will using SSL on the site (enabling "https") solve this problem? If not, then what will? (Realize that using something like PHPMailer is better, but mail() is much much simpler to implement so would prefer using it instead -- if at all possible.)
Error:
Script:
<?php
$to="receiver's email address";
$subject="sub: test mail from mail1.php";
$body="body: test mail from mail1.php";
$from = "sender's email address";
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
?>

Will using SSL on my site (enabling "https") solve this problem?
No. Whether or not the recipient server considers your email to be spam has nothing to do with whether or not the website on the server that sent the mail is using HTTPS. The encryption complaint has to do with your local email server, not your web server.
If not, then what will?
Note that the fact your email is in the spam folder is not necessarily because of the lack of encryption. Implementing encryption on your local email server may help but could be a pain -- you'd have to refer to the docs for whatever email server you're running.
You can likely improve your chances by implementing SPF and DKIM on your side.
PHPMailer will not necessarily fare any better. I would recommend a mail service like MailGun instead. They will take care of the SSL for you, and provide services like bounce detection.

Try sending header before the mail() function, for example:
$header = "From: noreply#example.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
.
.
.
mail($to,$subject,$body,$headers);
In case this doesn't fix your problem. Please try using PHPMailer instead.
Download the library from https://github.com/PHPMailer/PHPMailer

Related

Why am i able to send email from localhost using Swift Mailer but not with PHP's mail() function?

I am working on a MAMP PRO localhost server. I am very sure emails were being sent some months ago on my localhost from my local applications using php's mail() function. All of a sudden i can't get emails to be sent. I have even moved one of the local websites to a live server on GoDaddy but emails are still not being sent.
The GoDaddy guys swear to that nothing is wrong with their settings and that the issue has to be in my code. Getting back to my localhost MAMP PRO server, i tried all i could to debug, including messing around with the php.ini settings to no avail. I finally reluctantly decided to try an email library, so i went for Swift Mailer. I installed it, wrote the script and now emails are being sent from localhost. I assume it will also work if i put the code on the live server (at GoDaddy).
Here is my mail() code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: ". "$this->_headerFrom". "\r\n";
$headers .= "Reply-To: "."$email". "\r\n";
$headers .= "Return-Path: "."$email". "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$to = "$this->_applicationEmail";
$send = mail($to, $subject, $msg, $headers);
$subject and $msg are all set earlier in the script and they are strings
$send returns true, but no email is sent. I have followed all sorts of
examples here on SO to no avail. It's simple, but mind-boggling all the
same.
I really need to understand why. What is Swift Mailer doing that mail() isn't? I would rather keep my mail() scripts if only i could get them to work. The fact is, i had spent a lot of time writing custom email scripts with several email templates. It would be a heck of a task to rewrite all those mailing scripts to use Swift Mailer. What could make mail() stop working?
MAMP/WAMP need to be set up correctly to send mail.
See http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/.
The same for your GoDaddy server you probably need to do something with SMTP to make sure it is set up correctly.
You might need to do a few tests to see if mail is actually getting sent or just get flat out rejected as spam by the server receiving it as it won't have SPF etc,.

PHP email issue only working within my domain

I have a PHP code hosted on godaddy linux shared hosting
My script is sending email to my domain but not external domain.
I can send an email from hotmail to my domain but cannot send email from my domain to hotmail.
My domain is not listed as spam
Here is the PHP code I am using and working when sending to my domain.
headers = "From: webmaster#mydomain.com \n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
mail($email, $subject, $txt, $headers)
So why is it not getting delivered outside my domain?
I am able to send an email using the script but only on my own adress. me#myserver.com. When I receive it the from adress is wrong. Its not the one i have included in the headers
I'm guessing that your not authenticated your emails before sending (using SMTP). This is commonly blocked by mail servers as it cannot verify where the actual email is coming from. Try authenticating your emails using your SMTP credentials through your Godaddy server and see if that fixes it.
From their documentation,
Two non-CGI form mailers are included in Linux shared hosting account
default files: webformmailer.php and gdform.php. They reside in the
root directory of your hosting account. Incorporating either of these
scripts into your website creates a form to capture user information
and email it to a specified address
SPECIFYING AN EMAIL ADDRESS FOR THE PHP FORM MAILER
To use their PHP form-mailer, you must specify an email address where you want the contents of your form sent to.
Form-mailers cannot send from #aol.com, #gmail.com, #hotmail.com,
#msn.com, or #yahoo.com addresses.
To Specify the Email Address for the Form-Mailer
Log in to your GoDaddy account.
Click Web Hosting.
Next to the hosting account you want to use, click Manage.
In the Tools section of the Hosting Control Panel, click the Form
Mail icon.
Under the Forms Email Address section, type the email address you
want to use with your form-mailer.
Click Continue.
Verify that this is the address you want to use with your
form-mailer, and click Update.
For more information, Please read this page
UPDATE::
The best thing to do is check what PEAR extensions GoDaddy have on there hosting, if they have PEAR mail, you can use that. If not, then you should try using authenticated mail sending.
<?php
include('Mail.php');
$recipients = 'joe#example.com';
$headers['From'] = 'richard#example.com';
$headers['To'] = 'joe#example.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params['sendmail_path'] = '/usr/lib/sendmail';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($recipients, $headers, $body);
?>
Mail::send() – sends a mail

Mail Function not working in php

My mail function is not working. My mail function is as follows:
function sendmail($from,$to,$sub,$msg)
{
$subject=$sub;
$message=$msg;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'.$from.'>" . "\r\n";
mail($to,$subject,$message,$headers);
}
This works fine in some of my other project but not working in a new project of mine.
It may be mail not working in your server.
Check with a basic mail function and upload it in your root to test mail.
testmail.php
<?php
$msg = "This is test mail";
mail("tester#email.com","My subject",$msg);
?>
If mail not working then try with authenticated mail like phpmailer, sendmail.
PHP inbuilt mail() function wont work in ur localhost or the server WHICH DOES NOT support smtp server. If you are running this project in ur pc locally then this mail function wont work. you need to upload it in server and then try, it will work!
If you are running this project in server and your mail doesn't fire then possibilities are :
1) You are hosted it in Windows server which supports PHP but not smtp.
2) If server is Linux, then server might have disabled outgoing mail. pls contact your server
I suggest you to use PHPMailer [https://github.com/Synchro/PHPMailer] which sends mail through external SMTP server like GMail,Hotmail etc.. give it a try..
I finally solved the issue. The problem was I had given my gmail id as admin id ( i.e, from address) now i changed it to a mail id from the domain name(say, if the domain name is www.abc.com I gave id as noreply#abc.com) and it works.
And now i came to know that giving gmail or other mail ids will work in some cases in some servers but it wont work on all servers. So using mail id in domain name (noreply#abc.com) will solve this issue. Even though gmail ids works in some servers still it will give a error message in the body of mail or it will be a spam mail so it is better to use mail id derived from domain name like noreply#abc.com.
Thank You....

Mail being sent to gmail, yahoo, but not to personal mail servers

I am facing a weird problem. When I send out mails using PHP's mail() function, the mail is being sent perfectly to gmail and yahoo(though it was marked as spam in yahoo), but the mail is not received by my company's email address.
I don't have direct access to the server, only ftp to the public_html folder, hence I can't check the logs.....
Any ideas or suggestions?
EDIT:
$mailfrom="website#mysite.com";
$mailto=$buyerrow['email'];
$subject="Test Details";
$body='Hi '.$buyerrow['name'].'!<br>Test Details below:<br><br><br><br><br>Thanks<br>Web Team';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; carset=iso-8859-1;\r\n";
$headers.= "From: ADMIN <".$mailfrom.">\r\n";
#mail($mailto,$subject,$body,$headers,"-f website#mysite.com");
As for the spam folders at my company's server, I am quite sure it didn't end up there either....
Is it possible that there is some server setting which allows php to send mail to only particular server?
Many company mailservers are set up to outright reject some types of spam immediately during the SMTP session. If that happens, it will never make it to your companies spam folder. You should check with your company system administrator.
If you're in doubt, you can always use an application like Wireshark to capture and analyse the actual SMTP traffic.
Have you checked on the Spam folder ? also check whether you have set HEADERS properly with from name etc.,
The problem seems to be with your company's server mail server.
Make sure to test it [send email from yahoo to your company email address] and double check the mx records.

why is php mail script not sending mail

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example#gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>
but it does not actually send the mail please help me out with this
The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.
check the following -
check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).
Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.
My guess is if all the above are running, you are good to go.
please check following ** Please verify your servers sender domain policy**
Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.
ie use
$header = "From:example#/*yourhostname.domain name*/ \r\n";

Categories