简体   繁体   中英

sending mail from server php

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

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM