Cannot send mail through php

Reply

Join Date: Jun 2008
Posts: 9
Reputation: Andrew F. is an unknown quantity at this point 
Solved Threads: 0
Andrew F. Andrew F. is offline Offline
Newbie Poster

Cannot send mail through php

 
0
  #1
Jun 17th, 2008
Can you take a look at this:

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Untitled Document</title>
  5. </head>
  6.  
  7. <body>
  8. <?php
  9. $emai=$_REQUEST['txtemai'];
  10. $subj=$_REQUEST['txtsubj'];
  11. $mess=$_REQUEST['txtmess'];
  12. if (@mail($emai,$subj,$mess)) {
  13. echo('<p>Mail sent successfully.</p>');
  14. } else {
  15. echo('<p>Mail could not be sent.</p>');
  16. }
  17. ?>
  18. </body>
  19. </html>

I keep on getting the else statements.

Here's the code from the form page this email page works with:

  1. <form method="post" action="Emailed.php">
  2. <input name="txtemai" type="text" id="textfield" size="75" />
  3. </p>
  4. <p> Subject: </p>
  5. <p>
  6. <input name="txtsubj" type="text" id="textfield" size="75" />
  7. </p>
  8. <p>Message:
  9. <textarea name="txtmess" cols="87" rows="15" id="textarea"></textarea>
  10.  
  11. <input name="button" id="button" type="submit" value="Send" />
  12. </form>
  13. </p>

Here is my php.ini in the mail portion of it:

[mail function]
; For Win32 only.
SMTP = smtp.va.com
smtp_port = 25

; For Win32 only.
sendmail_from = Admin@va.com

I am using Apache 2.2.8 and Win XP Pro SP2

Can anyone find a solution why I can't send emails to my test address in yahoo.com?
Last edited by Andrew F.; Jun 17th, 2008 at 8:54 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Cannot send mail through php

 
0
  #2
Jun 17th, 2008
Is your smtp.va.com server a different server ? If so, are you sure it supports open relay smtp. Normally you would need to authenticate to able to send email. If it is the same server try localhost instead.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: Andrew F. is an unknown quantity at this point 
Solved Threads: 0
Andrew F. Andrew F. is offline Offline
Newbie Poster

Re: Cannot send mail through php

 
0
  #3
Jun 18th, 2008
Originally Posted by pritaeas View Post
Is your smtp.va.com server a different server ? If so, are you sure it supports open relay smtp. Normally you would need to authenticate to able to send email. If it is the same server try localhost instead.
I'm very sorry for the confusion but I'm not not yet live so I'm obliged to use localhost but it doesn't work it seems my problem is authentication. How do I solve this?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Cannot send mail through php

 
0
  #4
Jun 18th, 2008
I don't think mail() supports authentication. You can use the PHPMailer package. It's easy to use and well documented. You can find it on SourceForge.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: Andrew F. is an unknown quantity at this point 
Solved Threads: 0
Andrew F. Andrew F. is offline Offline
Newbie Poster

Re: Cannot send mail through php

 
0
  #5
Jun 18th, 2008
Originally Posted by pritaeas View Post
I don't think mail() supports authentication. You can use the PHPMailer package. It's easy to use and well documented. You can find it on SourceForge.
I tried your suggestion and took the very first code I laid my eyes on:

  1. <?php
  2. require_once("PHPMailer/class.phpmailer.php");
  3. $mail=new PHPMailer();
  4. $mail->IsSMTP();
  5. $mail->Host = "localhost";
  6. $mail->From = "****@****.com";
  7. $mail->AddAddress("****@yahoo.com");
  8.  
  9. $mail->Subject = "First PHPMailer Message";
  10. $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
  11. $mail->WordWrap = 50;
  12.  
  13. if(!$mail->Send())
  14. {
  15. echo 'Message was not sent.';
  16. echo 'Mailer error: ' . $mail->ErrorInfo;
  17. }
  18. else
  19. {
  20. echo 'Message has been sent.';
  21. }
  22. ?>

Output: Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.

I still seem to be encountering the problem I was having with vanilla mail.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Cannot send mail through php

 
0
  #6
Jun 18th, 2008
You may need to add:

  1. $mail->SMTPAuth = true;
  2. $mail->Username = "XXX";
  3. $mail->Password = "YYY";
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: Andrew F. is an unknown quantity at this point 
Solved Threads: 0
Andrew F. Andrew F. is offline Offline
Newbie Poster

Re: Cannot send mail through php

 
0
  #7
Jun 18th, 2008
Originally Posted by pritaeas View Post
You may need to add:

  1. $mail->SMTPAuth = true;
  2. $mail->Username = "XXX";
  3. $mail->Password = "YYY";
I added the lines, and just to play on the safe side I used my gmail account

  1. <?php
  2. require_once("PHPMailer/class.phpmailer.php");
  3. $mail=new PHPMailer();
  4. $mail->IsSMTP();
  5. $mail->Host = "ssl://smtp.gmail.com:465";
  6. $mail->SMTPAuth = true;
  7. $mail->Username = '****@gmail.com';
  8. $mail->Password = "*****";
  9. $mail->From = "*****s@gmail.com";
  10. $mail->AddAddress("*****@yahoo.com");
  11.  
  12. $mail->Subject = "First PHPMailer Message";
  13. $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
  14. $mail->WordWrap = 50;
  15.  
  16. if(!$mail->Send())
  17. {
  18. echo 'Message was not sent.';
  19. echo 'Mailer error: ' . $mail->ErrorInfo;
  20. }
  21. else
  22. {
  23. echo 'Message has been sent.';
  24. }
  25. ?>

Output: It didn't output anything!

I checked my test address at yahoo and no emails were added
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Cannot send mail through php

 
0
  #8
Jun 18th, 2008
$mail->Host = "smtp.gmail.com";

and I think

$mail->Port = 465;

But you'll have to check the manual.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: Andrew F. is an unknown quantity at this point 
Solved Threads: 0
Andrew F. Andrew F. is offline Offline
Newbie Poster

Re: Cannot send mail through php

 
0
  #9
Jun 19th, 2008
Originally Posted by pritaeas View Post
$mail->Host = "smtp.gmail.com";

and I think

$mail->Port = 465;

But you'll have to check the manual.
still nothing. Any ideas? I'm still open for suggestions
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Cannot send mail through php

 
0
  #10
Jun 19th, 2008
  1. $mail->SMTPSecure = "ssl";

This stuff can all be found by googling for it....
Can you be more specific about the error, perhaps it is something completely different.
Maybe try this one instead: http://www.klenwell.com/is/PhpGmailMailer
Last edited by pritaeas; Jun 19th, 2008 at 9:24 am.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 4516 | Replies: 20
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC