Saturday, April 20, 2013

Sending mail from XAMPP using PHPMailer

In reference to my earlier post "Sending mail from localhost using PEAR and WAMP",  i received few feedback that the same procedure was not working in XAMPP as they faced difficulty in installing PEAR package. So to send mail from localhost without any installation you can make use of PHPMailer library. I helped my friend and was successful in resolving the issue.

To Send mail from localhost using PHPMailer and XAMPP

  1. Install XAMPP (skip this step if you have already installed)
  2. Create your Project folder and download PHPMailer
  3. Extract class.phpmailer.php and class.smtp.php
  4. Locate php.ini (located under xampp/php/ folder or can be reached from xampp tray icon
  5. Seach for ;extension=php_openssl.dll and uncomment it.
  6. Open class.smtp.php search for the host and port and set the corresponding values.For Ex: $host="ssl://smtp.gmail.com" $port=465
  7. Now the code for sending mail can be found here.
If you still have any clarifications please comment below.

Stay tuned for more.

18 comments:

  1. Hi im still having truble
    I putt the line $mail->SMTPDebug =1;

    and I have this error log created
    SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1460627503)The following From address failed: xxxxx@gmail.com : Called Mail() without being connected Mailer Error:The following From address failed: xxxxx@gmail.com : Called Mail() without being connected

    ReplyDelete
    Replies
    1. Solved!

      Update path variable to use php

      Delete
    2. I am sorry but what does it mean exactly?

      Delete
  2. finally somethin' that actually works !

    ReplyDelete
  3. It worked immediately! Thank you for the crystal-clear a good info!

    ReplyDelete
  4. thank you very much it really worked for me

    ReplyDelete
    Replies
    1. when i try running the code ,the browser just keeps on connecting no output is obtained

      Delete
  5. Where do I change the values in class.smtp.php for host and port?

    ReplyDelete
  6. I got this error:
    Mailer Error: SMTP Connect() failed.

    ReplyDelete
  7. tengo este error:
    Warning: fsockopen(): unable to connect to ssl://smtp.gmail.com:25 (No route to host) in /Applications/XAMPP/xamppfiles/htdocs/jav/phpmailer/class.smtp.php on line 122

    ReplyDelete
  8. i got this erroe :Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\class.phpmailer.php on line 1466

    ReplyDelete
  9. i have this error path not found i changed my code to yours but it is not working
    it it shows this error

    ReplyDelete
  10. Solved: you need to include the both class.phpmailer.php and class.smtp.php in your sendmail script.

    Place the following two lines at the beginning of your sendmail-script:

    require_once "phpmailer/class.smtp.php";
    require_once "phpmailer/class.phpmailer.php";

    then you just have enter "host" and "port" in class.phpmailer.php:

    public $Host = 'your_host';
    public $Port = 25;//Portnumber 465 or 25

    I hope this helped....

    ReplyDelete
  11. I can't find the $host="ssl://smtp.gmail.com" $port=465 in class.smtp.php.. what should I do?

    ReplyDelete
    Replies
    1. if you downloaded the phpmailer link. inside the folder is class.smtp. open it and use crtl+f to find the $host and the $port.hope this helps

      Delete
  12. Where I can find my username and password for SMTP? please help me..

    ReplyDelete