I am trying to send out mails from my server without them getting into the junk folder when recieved in the other end. I did my research and found out that i should try out PHPMailer.
Now i've used 2 whole days crawling through the internet trying to come up with a solution to this problem. I want to send emails using googles free SMTP service. But cant get this to work at all.
All i get is the error msg : Could not connect to SMTP host
It also takes about 15 seconds before i actually get the error msg.
according to google this is how i should configure my settings:
http://mail.google.com/support/bin/answer.py?answer=13287
this is my code : (same as 10 other guidelines/tutorials i've found)
header('Content-Type: text/html; charset=utf-8');
require_once('../class.phpmailer.php');
require_once('../class.smtp.php');
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->SMTPKeepAlive = true;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->CharSet = 'utf-8';
$mail->Username = 'myadress#gmail.com'; // SMTP account username
$mail->Password = 'mypw';
$mail->SetFrom('myadress#gmail.com', 'My name');
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("reciever#live.no", "Reciever Name");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
So this is clearly not working. Should i contanct my isp? Or should i try something else? I really need to be able to send out emails without them going straight to the junk folder...
best of regards,
alexander
I am trying to send out mails from my server without them getting into the junk folder when recieved in the other end. I did my research and found out that i should try out PHPMailer.
wrong. You've not done your research properly.
If they are getting as far as the remote end then there's nothing intrinsically wrong with your code. Using phpmailer() isn't going to help. Using a different SMTP service may help - but doesn't help you understand what's really going on here.
The question of how to get remote system to NOT treat your email as spam has been asked and answered numerous times here:
try reading some of the many good answers to these other posts
there is no definitive answer - there are just too many factors and even if you knew exactly what they were you couldn't account for them all
all you can do is make your emails look less like spam
this is all about the content of te email and the way the email server / DNS is configured
Your messages are marked as Spam by software like "Spamassassins", there are a lot of things to know, your message is rated from Spamassassin, according to this list for the last version: SpamAssassin Tests
Get a look and you will easily understand why your message is marked as spam.
The Higher is the score you reach, the higher is the probability to be marked as spam, try to send it in plain text.
If you can't connect to SMTP it may not be code related at all. In fact, from the sounds of it, your code is working as far as trying to do what its supposed to - just failing.
Can your server access smtp.gmail.com on port 465 through any firewall you may have on your machine or network? Is it allowed to at the other end? (Does Google allow this kind of access?)
You could try using PuTTy or similar to access the mail server directly, and type in some SMTP commands to see what messages you're getting back.
If you have a local mail server running, i'd try it with that and send yourself some messages and work from there.
Once you can actually SEND an email, as alluded to in the other answers - you can start worrying about having it accepted by servers and not treated as spam!
It sounds like your problem is not related to anti-spam processing, but rather an inability to actually connect to the Google SMTP server. That's where I'd focus at this point. Long delays in responses usually lead me to check out possible DNS issues as the first step in troubleshooting. Are you able to ping smtp.gmail.com from your server? If the hostname gets resolved by DNS and you get a response, then check whether outbound port 465 is being blocked at your firewall.
Related
So I developed an automated Mailing System through which I send automated e-mails in PHP using the PHPMailer Extension.
First, most of the e-mails I've sent with the PHPMailer dropped into the spam of several clients, a well-known issue. I've checked with my host and we created an SPF record; and the result improved a lot.
Now by coincidence, I've found that some clients still seem to drop messages received via the PHPMailer script into their Spam folder. If I send the same e-mail manually, it doesn't happen, so it seems to be related to PHPMailer; so I must be doing something wrong.
The configs / code I'm currently using are / is :
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = $host; // verified with my host
$mail->Port = 465;
$mail->Username = 'mymail#mydomain.com'; // verified with my host
$mail->Password = 'mypassword'; // verified with my host
$mail->SMTPSecure = 'ssl';
$mail->SMTPAutoTLS = true;
$mail->setFrom( 'mymail#mydomain.com', 'This is the Header of the E-Mail' );
$mail->addAddress( 'recipientsmail#hisdomain.com', '' );
$mail->isHTML( true );
$mail->Subject = 'This is the Subject of the E-Mail';
$mail->CharSet = 'UTF-8';
$mail->Body = 'HTML Content of the E-Mail';
$mail->send();
$mail->SmtpClose();
Please note that my hosting provider does not support any DKIM signature authentication; and I've also verified the correct reverse DNS lookup with my provider.
What am I missing folks?
I interestingly came about this post here; which writes that "IANA has reassigned a new service to this port [465], and it should no longer be used for SMTP communications."
The article recommends the use of tls and port 587 should be the default approach. Is this maybe the issue; or am I missing something out on PHPMailer? I just wanna be sure before switching anything, as I'm not at all an expert in the area of e-mails.. And well, I've never heard about this port issue.
Whether mail ends up in spam is very difficult to control. Implementing SPF and DKIM can help, but still provide no guarantees. If it was easy to bypass spam filters, spammers would do it, and they would not be spam filters! There's an article in the PHPMailer wiki about avoiding spam filters that you may find helpful. The headers in a received message will often tell you why a message has been put in the spam folder, for example listing the spamassassin rules it matched.
You say it works "manually", but is that sending from the same place (e.g. on your local machine)? You can get the raw text of messages sent through each route and compare them to see what's different (other than obvious things like message IDs).
That MailGun article is outdated. Since then, RFC8314 has not only "undeprecated" port 465, it's now recommended as the default because it eliminates a possible attack vector in the pre-encryption stage that SMTP+STARTTLS uses on port 587. Unfortunately it also makes it harder to debug from PHP, and denies the chance to do opportunistic encryption when encryption is not requested explicitly, so it's not the default in PHPMailer (yet).
Okay, I'm at my whit's end here. I have a client whose site is hosted on GoDaddy and that uses Outlook. I've written a PHP script to send mail to one of their domain e-mail addresses from a contact form on their website.
I can get this e-mail to send to every single service except outlook/exchange/live/microsoft accounts.
I read that using PHPMailer was a good idea, so this is what I'm currently using to send mail:
//$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "a2plcpnl0287.prod.iad2.secureserver.net";
$mail->Port = 465;
$mail->Username = "test#alamohomefinance.com";
$mail->Password = "xxxxxxx";
$mail->SetFrom('yourname#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (hotmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = "jakerevans2#live.com";
if(!$mail->Send()) {
error_log("Error from calculator!". $mail->ErrorInfo);
} else {
error_log("Success from calculator!");
}
This e-mail gets sent to my gmail account and some others, but not to my .live account or my client's Outlook address.
I've tried everything I've found on the internet so far, nothing is working. Any ideas or thoughts anyone?
Thanks!
EDIT:
The Godaddy server has an SPF record that reads: v=spf1 include:spf.protection.outlook.com -all
I've created a DKIM key from https://www.port25.com/dkim-wizard/ and added a DKIM TXT record to GoDaddy, with the following details:
Host: key1._domainkey.alamohomefinance.com
TXT Value: k=rsa\; p=MIIBIjA...
I've added a DKIM record, with the following details:
Name: _dmarc.alamohomefinance.com
TXT Value: v=DMARC1; p=quarantine; sp=none; ruf=mailto:user#example.com; rf=afrf; pct=100; ri=86400
Am testing now to see if these changes make a difference...
First up, you should look at the PHPMailer troubleshooting guide, which has a little section on GoDaddy, and many other problems.
You will get much better feedback on what's going on if you enable debug output of server messages, so set SMTPDebug = 2, and see what it says.
GoDaddy is known to block outbound SMTP, and generally will either simply fail to connect (see many questions on SO about that), or cause TLS verification failures as you get redirected transparently to their mail servers.
In your code you've got the smtp.live.com Host, but this username:
$mail->Username = "a2plcpnl0287.prod.iad2.secureserver.net"
secureserver.net is the domain used for GoDaddy's mail servers, and that user name is the name of an actual GoDaddy mail server, so it seems very unlikely that you should be using it as a user id for live.com, especially since GoDaddy will be rotating mail servers frequently, so you're unlikely to get the same one every time - is that really your login ID for live.com?
I'm also suspicious of the phrasing of your question: you do not need to connect to live.com to send email to live.com - there's nothing stopping you sending to a live.com address from a connection through gmail, so it sounds like you may have a conceptual issue. The Host, Username and Password properties are for the mail server that you send out through, not that you are sending mail to.
As I said, normally GoDaddy doesn't allow remote SMTP at all, so I'm very surprised if you've had it working without using a GoDaddy mail server, so I suspect you've had something else work, not what you think.
I can also see you've based your code on an obsolete example, so make sure you're running the latest PHPMailer.
Update:
I noticed something critical. The code does not call $mail->isSMTP();. This means that it's not using SMTP at all, it's using the default mail() function, and as such none of the SMTP config makes any difference at all. The message will be submitted to your local mail server, which will then relay through GoDaddy's server. Look in your mail server's log file to see what's happening, usually in /var/log/mail.log or similar.
Check your server ip on http://mxtoolbox.com/blacklists.aspx . I've noticed Microsoft is very picky about blacklisting. I've had this issue with a brand new I.P addresses that were acquired with an apparent bad rep. If your on godaddy on a shared account ip it's very likely either the ip or entire subnets are blocked by default.
After setting up SPF Record i still am here to verify why i cannot recieve this email to hotmail account. I am able to send it to gmail with no issues. Please confirm if the code is correct, and SPF record is correct:
<?php
require_once 'PHPmailer/class.phpmailer.php';
$mail = new PHPMailer();
$body = "Thankyou for your Purchase. <br/><br/> Here is your Policy! You are now Protected during your Travels.";
$mail->AddAddress('$payer_email');
$mail->From = "noreply#example.com";
$mail->FromName = "Name";
$mail->Subject = "Thankyou for Your Purchase";
$mail->MsgHTML($body);
$mail->AddAttachment("tosend/xxx.pdf");
if(!$mail->Send()) {
echo "There was an error sending the message";
$sql = "UPDATE purchases SET policy_sent = 'Not Sent' WHERE id = '$lastid' ";
$stmt = $mysqli->query($sql);
$mysqli->close();
exit;
}
echo "Message was sent successfully";
$sql = "UPDATE purchases SET policy_sent = 'Sent', email_to = '$payer_email' WHERE id = '$lastid'";
$stmt = $mysqli->query($sql);
$mysqli->close();
?>
Here is the SPF:
v=spf1 a mx include:secureserver.net ~all
Are all these correctly configured?
Use SMTP Auth, then Hotmail wouldn't complain anymore. Anonymous mails are considered as spam by almost all receiving servers.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
But ofc. depending on whether you have control over your SMTP or not, you should make sure, that basic stuff like reverse-dns-lookup is setup properly
Due to the discussion in the comments, I want to add a little bit more information about my thinking about why SMTP Auth will fix this:
IF you are using PHPMailer without the definition of an SMTP-Server, PHPMailer will operate in mail mode, which will just call the mail() function of php.
The mail-function itself will use the smtp-settings configured in the PHP-INI file, or the default values, which are listed here: http://php.net/manual/en/mail.configuration.php
defaults:
SMTP = "localhost"
smtp_port = "25"
Since the OP has configured a local mail server (or why would he setup MX-records?), php will now connect to this SMTP-Server without Authentication. The Server will accept the message and send it to the next server.
(Same applies if unix' sendmail is used)
Each Server in the chain and especially the receiving server can now see, that a private SMTP has been used and no Authentication has been provided.
That is already Spam-Score over 9000 because with a setting like that (theoretically) everyone could use that server to send mails!
Restrictions like only from localhost are ofc. not known by other servers, therefore that SMTP is considered to be an Open Mail Relay http://en.wikipedia.org/wiki/Open_mail_relay
Switching PHPMailer to SMTP-Auth (EVEN if still the local SMTP Server is used) will add This information to the Entry created by the server when forwarding the mail. The Entry will look like this:
Received: from SERVER1 ([xxx.xxx.xxx.xx]) by mydomain.de with ESMTPA
The trailing A after ESMTPA now tells the receiving Server, that Server1 has used a valid user account on mydomain.de to start the sending-attempt, which means that the SMTP-Server knows the origin of the mail and could provide information about the sender.
Still, the local SMTP-Server is not a known one, so in this case it might end up beeing greylisted and checked on various RBLs, which shouldn't be any problem in this case.
If the (local) SMTP-Server now passes ALL checks (Reverse-DNS Lookup, Greylisting, RBLs and what not) - the mail has a good chance to be successfully delivered, even if no remote smtp is used, because the server could be successfully authenticated as well as the sender using that server. (Otherwise no company could setup own servers)
So, using SMTP-Auth (Or any other authentication method) will also have an impact, even if no remote-SMTP Server is used.
Authenticated Mails are not a guarantee for not beeing considered as spam - but unauthenticated Mails are definitly ranked higher in the Spam-Score of common systems.
Had the same issue. I have checked the whole script 30 times. Each setting each . and , Checked and rechecked dns records dkim and spf 100 times.
Nothing worked.
I e-mailed hotmail/outlook/live about the issue. I didn't expect any help but within a few hours the problem was solved.
It wasn't in the script. Hotmail just blocks any e-mail that is sent trough most webpages. Even if your spam reputation is fine. They have placed the server's ip on a whitelist and the problem was solved.
They can change it back if they detect bad behavior. There's a limit for sending e-mail. If your server has a bad reputation they aren't likely to add the server to their whitelist. This can be an issue on shared hosting packages. Someone else on the same server where you host your website can f up the servers reputation.
Have you tested on a live server? If yes, what error did you get?
Have you enabled your phpmailer's debug to know what errors it has? If you are not using SMTP you can test with this
$mail->do_debug = true;
If you are using SMTP then use
$mail->SMTPDebug = true;
What output did you get from your debugger? You get a clue to where your problem is coming from from there.
I also suppose #dognose's answer by asking you to better use SMTP. That way your email passes through an authentication which would help indicate your identity was confirmed.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
If $mail->Port = 26; doesn't work you can try $mail->Port = 25;.
The SPF currently being published by your DNS is invalid because you have three records!:
# dig +short txt immortalinsurance.com
"v=spf1 a mx include:smtp.secureserver.net ~all"
"v=spf1 mx mx:v=spf1 a mx include:secureserver.net ~all include:secureserver.net -all"
"\"v=spf1 a\""
The first one is valid; You should delete the second two.
The content of this record is correct for your domain if you are sending mail from 182.50.130.73. The 'mx' stanza is not strictly necessary since it points at secureserver.net anyway, but it may save DNS lookups on receiving servers.
Before you start sending email using mail() or SMTP, make sure you create valid sender email account in your cpanel.
From = "noreply#immortalinsurance.com";
This is very important if not all emails you send will be tagged as SPAM and goes to junk.
Once this is done, you must setup domainkeys and SPF records. Having a dedicated IP instead of using shared given by your hosts will also help with the delivery.
Finally check your mail with all three major email providers such as Hotmail, Yahoo and Gmail.
You will probably have to break down the exact reason why step by step. I know for a fact Hotmail is using a rules based spam filter (which is quite strict) and Gmail uses more like a self-learning system, which could explain why Gmail accepts your message and Hotmail doesn't.
The following you can check though:
A spf-record only works on the domain the spf record is added and only works for mail sent from ips/domains defined in that spf. Therefore make sure your code is executed from a server that exists in your spf.
Using SMTP as proposed above can increase derliverability (but it really depends on the receivers' spam filter). If you're testing on a local server though, you can use SMTP to send the mails trough a mail server defined in the spf. Otherwise
If the mailserver you are using is an open relay, than that could (and probably would) be a reason to add extra spam points. Thus make sure you're using a closed relay (e.g. the mailserver you're using doesn't allow mails to be sent unauthenticated users)
Check if the mailserver you're sending from isn't on any blacklist (http://mxtoolbox.com/blacklists.aspx offers a great tool);
Use the message headers in Gmail to find out if Gmail sees any reason to add spam points to your message (Howto: https://support.google.com/mail/answer/22454?hl=en). There you can find if your spf works (by searching for 'spf=pass'). This might also work for Hotmail if your mail would be delevered into the spam folder.
One of the many rules spamfilter apply are keyword checking (which I think your mail contains a few off), the amount of text and such. Make sure the overall quality of your message is good;
PHPMailer uses php's mail function by default. You can change this to sendmail ($mail->isSendmail();, probaly doesn't work on Windows if sendmail is not set up properly) or perhaps check the settings of your php.ini what mailserver is used (use ini_set('SMTP', 'yourhost.com'); to override, but this only works on Windows as far is I know).
The user of the connection data $mail->Username must be the same as the $ mail->From, otherwise hotmail rejects the email or marks it as spam.
Also, if the email has images, it can also be marked as spam.
In summary, for everything to be perfect, send email without images and that the From is the same as the Username.
I'm using the mail() basic example modified slightly for my user id and I'm getting the error "Mailer Error: Could not instantiate mail function"
if I use the mail function -
mail($to, $subject, $message, $headers);
it works fine, though I'm having trouble sending HTML, which is why I'm trying PHPMailer.
this is the code:
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
print ($body ); // to verify that I got the html
$mail->AddReplyTo("reply#example.com","my name");
$mail->SetFrom('from#example.com', 'my name');
$address = "to#example.com";
$mail->AddAddress($address, "her name");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Try using SMTP to send email:-
$mail->IsSMTP();
$mail->Host = "smtp.example.com";
// optional
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';
Your code looks good, did you forget to install PostFix on your server?
sudo apt-get install postfix
It worked for me ;)
Cheers
This worked for me
$mail->SetFrom("from#domain.co","my name", 0); //notice the third parameter
$mail->AddAddress($address, "her name");
should be changed to
$mail->AddAddress($address);
This worked for my case..
You need to make sure that your from address is a valid email account setup on that server.
If you are sending file attachments and your code works for small attachments but fails for large attachments:
If you get the error "Could not instantiate mail function" error when you try to send large emails and your PHP error log contains the message "Cannot send message: Too big" then your mail transfer agent (sendmail, postfix, exim, etc) is refusing to deliver these emails.
The solution is to configure the MTA to allow larger attachments. But this is not always possible. The alternate solution is to use SMTP. You will need access to a SMTP server (and login credentials if your SMTP server requires authentication):
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.example.com"; // set the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "johndoe#example.com"; // SMTP account username
$mail->Password = "********"; // SMTP account password
PHPMailer defaults to using PHP mail() function which uses settings from php.ini which normally defaults to use sendmail (or something similar). In the above example we override the default behavior.
The PHPMailer help docs on this specific error helped to get me on the right path.
What we found is that php.ini did not have the sendmail_path defined, so I added that with sendmail_path = /usr/sbin/sendmail -t -i;
In my case, it was the attachment size limit that causes the issue. Check and increase the size limit of mail worked for me.
Seems in my case it was just SERVER REJECTION. Please check your mail server log / smtp connection accessibility.
I had this issue, and after doing some debugging, and searching I realized that the SERVER (Godaddy) can have issues.
I recommend you contact your Web hosting Provider and talk to them about Quota Restrictions on the mail function (They do this to prevent people doing spam bots or mass emailing (spam) ).
They may be able to advise you of their limits, and if you're exceeding them. You can also possibly upgrade limit by going to private server.
After talking with GoDaddy for 15 minutes the tech support was able to resolve this within 20 minutes.
This helped me out a lot, and I wanted to share it so if someone else comes across this they can try this method if all fails, or before they try anything else.
An old thread, but it may help someone like me. I resolved the issue by setting up SMTP server value to a legitimate value in PHP.ini
I had this issue as well. My solution was to disable selinux. I tried allowing 2 different http settings in selinux (something like httpd_allow_email and http_can_connect) and that didn't work, so I just disabled it completely and it started working.
I was having this issue while sending files with regional characters in their names like: VęryRęgióńął file - name.pdf.
The solution was to clear filename before attaching it to the email.
Check if sendmail is enabled, mostly if your server is provided by another company.
For what it's worth I had this issue and had to go into cPanel where I saw the error message
"Attention! Please register your email IDs used in non-smtp mails through cpanel plugin. Unregistered email IDs will not be allowed in non-smtp emails sent through scripts. Go to Mail section and find "Registered Mail IDs" plugin in paper_lantern theme."
Registering the emails in cPanel (Register Mail IDs) and waiting 10 mins got mine to work.
Hope that helps someone.
A lot of people often overlook the best/right way to call phpmailer and to put these:
require_once('../class.phpmailer.php');
or, something like this from the composer installation:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "../../vendor/autoload.php";
on TOP of the page before calling or including anything else. That causes the "Could not instantiate mail function"-error by most folks.
Best solution: put all mail handling in a different file to have it as clean as possible. And always use SMTP.
If that is not working, check your DNS if your allowed to send mail.
My config: IIS + php7.4
I had the same issue as #Salman-A, where small attachments were emailed but large were causing the page to error out.
I have increased file and attachments limits in php.ini, but this has made no difference.
Then I found a configuration in IIS(6.0), and increased file limits in there.
Also here is my mail.php:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../_PHPMailer-master/src/Exception.php';
require '../_PHPMailer-master/src/PHPMailer.php';
try{
$email = new PHPMailer(true);
$email->SetFrom('internal#example.com', 'optional name');
$email->isHTML(true);
$email->Subject = 'my subject';
$email->Body = $emailContent;
$email->AddAddress( $eml_to );
$email->AddAttachment( $file_to_attach );
$email->Send();
}catch(phpmailerException $e){echo $e->errorMessage();}
future.
We nee to change the values of 'SMTP' in php.ini file
php.ini file is located into
EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini
I have written a basic script for the mail functionality.
I am trying to run this script through WAMP server.
<?php
phpinfo();
$to = "mss#xyz.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "mohan.s#xyz.com";
$headers = "From: $from";
$res= mail($to,$subject,$message,$headers);
echo " $res Mail Sent.";
?>
I have set the SMTP, sendmail_from in the php.ini file .
It gives me the following error
Warning: mail() [function.mail]: Failed to connect to mailserver at
"mucse409.eu.xyz.com" port 25, verify your "SMTP" and "smtp_port"
setting in php.ini or use ini_set() in C:\wamp\www\email.php on line 9
Mail Sent.
I am able to ping the SMTP address from my machine. Please guide me.
Can you also send mail from this machine to this smtp server using some mail client like ms outlook or mozilla thunderbird?
I had a problem once that my provider block traffic directed at smtp ports outside due to virus infection, and I couldn't send mail because of this, but I could ping server and port.
Could be blocked by a firewall or some such.
See if you can open port 25 with telnet (If you don't have software for this, you can download putty)
Following this tutorial I was able to send mail link text.
Send email using Gmail and PHPMailer The new automatic update
generator is ready, it has been a long time since OCRALight has been
finished and little bit of this and that has been polished on the
update generation.
The process is fairly complex, it involves reverse-engineering,
data-mining, packaging, distribution and a lot o fighting with our
crappy Windows server that is between me and the final Linux
liberation.
Every step in the road has been automatized, one by one, every problem
has been solved and polished, now the final piece is in his place, the
automatic email generation. Now the updates will be made and send
everyday, even weekends and vacations.
If you are interested in the technical aspect keep reading:
How it has been done:
First of all, you need to have PHP with OpenSSL support, for Windows
you’ll need to Install PHP and carefully select OpenSSL in the
components list, if you already have PHP installed, don’t worry a
re-install will keep your configuration, and you’ll be able to select
OpenSSL.
Then download PHPMailer, and extract it near your main php
file.
You will need to have a Gmail account(obviously) I recommend you to
make a new one just for this, mainly because the configuration need to
be very precise, and you wouldn’t be able to use it freely without
loosing functionality or risking to break the configuration.
Configure your Gmail account to use POP mail, but not IMAP, ONLY POP,
just POP.
And now the code:
<?php
require(”PHPMailer/class.phpmailer.php”);
$update_emails = array(
‘Juan Perez’ => ‘Juan_Perez#jalisco.gob.mx’,
‘Francisco Garcia’ => ‘fgarcia#hotmail.com’,
‘Diana la del Tunel’ => ‘diana#gmail.com’
);
echo “\nSending Update Email\n”;
$mail = new PHPMailer(); // Instantiate your new class
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = “smtp.gmail.com”; // specify main and backup server
$mail->SMTPSecure= ’ssl’; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected
$mail->Username = “youremail#gmail.com”; // SMTP username, you could use your google apps address too.
$mail->Password = “yaourextremelynotlamepassword”; // SMTP password
$mail->From = “youremail#gmail.com”; //Aparently must be the same as the UserName
$mail->FromName = “Your name”;
$mail->Subject = ‘The subject’;
$mail->Body = “The body of your message”;
foreach ($update_emails as $name => $email) {
$mail->AddBcc($email, $name);
}
if(!$mail->Send())
{
echo “There was an error sending the message:” . $mail->ErrorInfo;
exit;
}
echo “Done…\n”;
?>
In this code I send the email to a group of people, thus I use the
“Bcc:” field instead of the “To:” one, to add a “To:” you would use
AddAddress($email, $name).
A possible upgrade would be to use a MySQL database to store the
addresses, and provide a web interface to add and remove
them. for the moment, this is enough.
Soo remember:
PHP with OpenSSL; PHPMailer; Create a Gmail Account; Activate POP Host:
smtp.gmail.com; SMTPAuth=true; SMTPSEcure=ssl; Port: 465; User with Domain;
Password; $Mail->send();