Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1

    Why can't I send mail from PHP - Apache?


    Hello again, I need send mail from PHP, I got Apache, PHP 5.3.3, I don't know why I can't send mails, this is my code in PHP:

    Code:
    <?php
    
    include_once("class.phpmailer.php");
    
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->Host = "smtp.live.com";
    
    $mail->SMTPSecure = "smtp.live.com";
    $mail->Port = 25;
    
    $mail->Username = "example1@hotmail.com";
    $mail->Password = "example1";
    
    $mail->AddAddress("example2@hotmail.com");
    $mail->From = "example1@hotmail.com";
    $mail->FromName = $_POST['SalesPartner'];
    $mail->Subject = "Hello Website";
    $mail->IsHTML(true);
    $mail->Body =' name: '. $_POST['name']. "<br />".'email: ' .$_POST['email']. "<br />". 'Phone: ' .$_POST['phone']. "<br />".'Comments: '. $_POST['comments']; 
    
    if($mail->Send()) {
    echo "Message sent! Thanks for your comments!";
    } 
    else{
    echo "No Message :(";
    }
    ?>
    This is save as mail.php, and when I put on my web localhost/mail.php
    I see nothing.

    Thanks for the help.
    Last edited by cuervo; January 8th, 2015 at 09:03 AM.
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Do you have the right path for the include file?
    If you run this script from the command line, does it work or produce an error (also check your http error log)?
    If you echo the values to screen, are they populated as expected?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    Thanks for the reply.

    Yes it the correct right path.

    I am working on centos 6.5, I never use some IDE to see an error in the code, right now I am downloading eclipse plataform, to see errors, one question, I need configure php.ini ?.

    I am new in php, but I think I need configure php.ini.

    Thanks for the help.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    No error, I don't know what is wrong with my code.

    Thanks for the help.
  8. #5
  9. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    You shouldn't need to configure the php.ini file.
    When you say that you see nothing, do you mean that the screen is just white?
    If so, there must be an error in the code somewhere.
    May I suggest some debugging is in order.
    Firstly, comment out every line with the exception of one of the echo statements and save the file. Do you see the echo'd text?
    If you do, line by line, remove a comment until you no longer see the echo'd text, at which point, you know which line is causing the error and should be able to fix it.
  10. #6
  11. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    The error is in the line:-
    $mail->Body =' name: '. $_POST['name']. "<br />".'email: ' .$_POST['email']. "<br />". 'Phone: ' .$_POST['phone']. "<br />".'Comments: '. $_POST['comments'];

    Check your quotes ...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    967
    Rep Power
    20
    Originally Posted by badger_fruit
    $mail->Body =' name: '. $_POST['name']. "<br />".'email: ' .$_POST['email']. "<br />". 'Phone: ' .$_POST['phone']. "<br />".'Comments: '. $_POST['comments'];
    Not sure if there is really an error in there. I couldn't find one, nor did my editor define anything incorrectly. (Maybe just never saw it) However, it IS a mess.

    Cuervo, I was wondering what your view/understanding on the difference between single and double quotes is...?

    Cleaner options: (I prefer the 2nd, since I like keeping things separated.)
    $mail->Body ="Name: $_POST['name']<br />\nE-mail: $_POST['email']<br />\nPhone: $_POST['phone']<br />\nComments: $_POST['comments']";
    $mail->Body ="Name: " . $_POST['name'] . "<br />\nE-mail: " . $_POST['email'] . "<br />\nPhone: " . $_POST['phone'] . "<br />\nComments: " . $_POST['comments'];
    (Used to be in PHP, but it displayed the first option's coloring poorly.)
    Last edited by Triple_Nothing; January 8th, 2015 at 08:35 AM.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  14. #8
  15. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Sorry triple_nothing, you're right and it was mis-read by myself (missed a ' which indeed now makes it error-free), I think as it is a mess of single and double quotes that didn't help, sorry for the red-herring!
  16. #9
  17. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    So i tried my own suggestion of commenting out the code and un-commenting a line at a time and it worked all the way through.
    I can only guess then that the problem is in the web.php file or the way you're adding this snippet into it.
    Can we see the full code please?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    Hello, thanks for helping.

    It was my mistake, web.php has nothing in common here, my code in the top of this post is the full code and it is mail.php, when I execute mail.php on localhost/web.php that code mail an email to example2@hotmail.com , I don't know why don't work, you paste the code and work?.

    Thanks for the help
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    I am trying to send email in centos platform, like this:

    [root@localhost html]# ssmtp example2@hotmail.com
    Subject: Test SSMTP
    Email send
    via SMTP
    ssmtp: Cannot open mail:25

    I think that is the port 25 that can not open, maybe is the configuration of ssmtp.conf?

    Thanks for the help.
  22. #12
  23. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Originally Posted by cuervo
    when I execute mail.php on localhost/web.php that code mail an email to example2@hotmail.com , I don't know why don't work
    What do you mean, this doesn't make any sense.
    Are you saying when you run this code on your localhost, it works but when you move it to a live webserver, it doesn't?
    If so, check the versions of php on each and make sure they're the same, you might need to create a phptest.php file with the content below to check:
    PHP Code:
    <?php phpinfo(); ?>

    Originally Posted by cuervo
    you paste the code and work?.
    Yes, of course, it doesn't send an email but as there's no actual credentials provided I get the text on screen saying "No message" which indicates that the code is good but something went wrong and $mail->send() returned false.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    Originally Posted by badger_fruit
    What do you mean, this doesn't make any sense.
    Are you saying when you run this code on your localhost, it works but when you move it to a live webserver, it doesn't?
    It was a typing error, should be localhost/mail.php, and my PHP version is 5.3.3 , when I put on my web localhost/mail.php I see nothing.

    And in my last post I have an error of port 25, and I enable the port 25, I don't know what is the problem, maybe ssmtp.conf.

    Thanks for the help.
  26. #14
  27. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Is the PHP version the same on both your local host and the web server?
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    122
    Rep Power
    1
    Yes, I think is a problem of sstmp.conf , need add ports I think.
Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo