+ Reply to Thread
Results 1 to 4 of 4

Thread: Email mail() Alternative

  1. #1
    cybrax's Avatar
    cybrax is offline x10 Elder cybrax is on a distinguished road
    Join Date
    Aug 2009
    Location
    UK
    Posts
    699

    Email mail() Alternative

    Using the built in PHP mail() function here at X10 is all very well for most people but sometimes users run into the problem of mail 'bouncing' from the likes of Hotmail and Yahoo. This is because of the shared servers previous misuse at the hands of spammers has resulted in them being blacklisted and there is little that can done about it.

    Thankfully there is way to send email from a website without using the mail() function with the aid of PHP sending the email via Google Gmail and it is remarkably simple to do.

    Gmail of course does have limits for how many messages can be sent each day (think it's around 500) to stop spamming. For a website contact form or small newsletter it should be more than enough.

    For more information Google "Php Mailer Class"
    the download link for phpmailer is http://sourceforge.net/projects/phpmailer/

    PHP Code:
    <?php

    // example on using PHPMailer with GMAIL

    include("class.phpmailer.php");
    include(
    "class.smtp.php"); // note, this is optional - gets called from main class if not already loaded

    $mail             = new PHPMailer();
    $YourName            "youremail@gmail.com";     
    $YourPass            =  "Your Gmail Password"

    $SendMailTo          ="somebody@wherever.com";    // email address to send message to
    $body             file_get_contents('contents.html'); // message contents using remote HTML file
    $body             eregi_replace("[\]",'',$body);

    $mail->IsSMTP();
    $mail->SMTPAuth   true;                      // enable SMTP authentication
    $mail->SMTPSecure "ssl";                     // sets the prefix to the servier
    $mail->Host       "smtp.gmail.com";          // sets GMAIL as the SMTP server
    $mail->Port       465;                        // set the SMTP port

    $mail->Username   $YourName;                    
    $mail->Password   $YourPass;                          

    $mail->From       =  $YourName;    
    $mail->FromName   "Webmaster";                
    $mail->Subject    "This is the subject";        // put whatever you like
    $mail->AltBody    "This is the body when user views in plain text format"//Text Body // put whatever you like
    $mail->WordWrap   50;                         // set word wrap

    $mail->MsgHTML($body);

    $mail->AddReplyTo($YourName,"Webmaster");// put whatever you like

    $mail->AddAttachment("/path/to/file.zip");             // optional attachments
    $mail->AddAttachment("/path/to/image.jpg""new.jpg"); // optional attachments

    $mail->AddAddress$SendMailTo,"First Last");

    $mail->IsHTML(true); // send as HTML

    if(!$mail->Send()) {
      echo 
    "Mailer Error: " $mail->ErrorInfo;
    } else {
      echo 
    "Message has been sent";
    }

    ?>
    Simply fill in your own Gmail account details, the recipients email address and add the file message.html then away you go it really is that easy.

    Attachments for zip folders or images are of course optional just comment out the lines if you do not want to use them.

    Have fun and please use responsibly.
    Google is like a sleeping bear, if you are quiet and do not annoy it then it will leave you alone. Wake it and it will eat you alive.
    The code must flow.
    Project 157: Latest UK Jobs direct to your mobile phone
    New Domain under construction: Lovelogic.net
    home for some new projects that we can't keep here ;)


  2. #2
    techairlines's Avatar
    techairlines is offline x10 Flyer techairlines has much to be proud oftechairlines has much to be proud of
    Join Date
    Jul 2009
    Location
    New York City
    Posts
    2,853

    Re: Email mail() Alternative

    Thanks for this tutorial. I'm sure many will find it useful.

    I would also like to add that this works with Google Apps accounts so you can send mail using @yourowndomain.com. Simply enter your Google Apps email address (such as admin@x10email.com) and password and it will work just like a normal Gmail account.
    Best regards,
    Brian Yang - TechAirlines


    How am I doing? Click the star button at the bottom left to rate this post. Thanks.
    Terms of Service | Account Portal | Wiki

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Email mail() Alternative

    Thanks. Have been using PEAR::Mail but that involves downloading PEAR and other requirements.
    Nothing is always absolutely so.

  4. #4
    cuatrosolesvideo54 is offline x10Hosting Member cuatrosolesvideo54 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    2

    Re: Email mail() Alternative

    great tutorial bro!

+ Reply to Thread

Similar Threads

  1. Can't send email to MSN mail
    By assurancehome in forum Free Hosting
    Replies: 0
    Last Post: 04-21-2010, 11:29 AM
  2. Can't send email using Squirrel Mail Webmail
    By heitorfer in forum Free Hosting
    Replies: 1
    Last Post: 03-25-2010, 10:36 AM
  3. Replies: 0
    Last Post: 04-16-2009, 12:47 AM
  4. Replies: 4
    Last Post: 11-14-2007, 02:46 PM
  5. Replies: 1
    Last Post: 10-21-2007, 12:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers