0
votes

I am attempting to send emails using phpMailer and GMail SMTP. It works fine sending emails to other Gmail accounts but sending to Yahoo the mail never gets there. I read about debugging using ip addresses and such, but I am not skilled in that area?

here is the code:

  $mail->Mailer='smtp';

   try {
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 587;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "__email__";  // GMAIL username
    $mail->Password   = "__pass__";            // GMAIL password
    $mail->SMTPDebug  = 2;

    $a = md5(uniqid(rand(), true)); //create a unique validation code

    //These are the variables for the email

    $mail->AddAddress (trim($_POST['email']),trim($_POST['username'])); // this is the email address collected form the form
    $mail->Subject = "Registration"; // Subject
    $mail->Body = "Thank you for registering\n your security code is ".$a;
    $mail->Send();


    echo "check your email to complete registration"; 
   } catch (phpmailerException $e) {
     echo $e->errorMessage(); //Pretty error messages from PHPMailer
   } catch (Exception $e) {
     echo $e->getMessage(); //Boring error messages from anything else!
   }

   $mail->ClearAddresses();

update: Found the problem: Our server had been blacklisted by Yahoo (not my fault) so that's a day-and-a-half wasted.

2
Are you sure the mails don't get caught in a spam filter? Can you check?Pekka
yeah first thing I checked. No mails anywhere.JIStone

2 Answers

0
votes

Since it's working with Gmail users my guest would be that some phpMailer is not sending your username and password properly. The gmail server won't accept to relay email if you are not authenticated.

One question, why don't you use your own email server, it would help to debug and to know why the emails are not sent.

0
votes

Instead of gmail I would advise you to use Google App Engine's email service. It does all the heavy lifting for you. Also because gmail has a send limit while app engine's is much higher. It also has a generous free quota(1000 recipients/day.

Here's an example of sending a message from the current signed-in user, using the login_required annotation to redirect the user to the sign-in page if they are not signed in:

from google.appengine.api import mail
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import login_required

class InviteFriendHandler(webapp.RequestHandler):
    @login_required
    def post(self):
        to_addr = self.request.get("friend_email")
        if not mail.is_email_valid(to_addr):
            # Return an error message...
            pass

        message = mail.EmailMessage()
        message.sender = users.get_current_user().email()
        message.to = to_addr
        message.body = """
I've invited you to Example.com!

To accept this invitation, click the following link,
or copy and paste the URL into your browser's address
bar:

%s
        """ % generate_invite_link(to_addr)

        message.send()