rodrigo7x Posted April 18, 2009 Share Posted April 18, 2009 Hi, I hope someone could shed some light on my dilema. I have php, apache, mysql and pear install on a local environment. I would like to be able to send emails through php but I can't. I started with this code: <?php $to = "Myownemailaddress"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> and I got the error 550 saying server requires authentication. So I google that and I found out about PEAR and installed it, I downloaded the mail, net_smtp, and net_socket classes so that the Mail.php function would work. I kept getting some errors about the require_once(Mail.php) could not be found... So I kept digging and when I found an updated version to all the dependencies the erros went away. Now when I use the following code, I don't get a confirmation saying it was successful neither do I get any error messages: <?php require_once "Mail.php"; $from = "Myownemailaddress"; $to = "Myownemailaddress"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "outgoing.verizon.net"; $username = "myusername"; $password = "mypassword"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> Now, pear I believe is installed right because I ran a test with text-highlighter class and the text displays properly as the test is supposed to. Can anybody see any errors in my code, or where I could have messed up? I installed pear in c:php\pear and I have that as the include_path in php.ini . I also set php.ini to : [mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 SMTP = outgoing.verizon.net smtp_port = 25 ; For Win32 only. sendmail_from = Myemailaddresshere the include path: ; Windows: "\path1;\path2" ;include_path = ".;c:\php\includes" include_path = ".;C:\php\PEAR" I greatly appreciate any help. Thank you. Link to comment https://forums.phpfreaks.com/topic/154580-sending-email-via-php/ Share on other sites More sharing options...
revraz Posted April 18, 2009 Share Posted April 18, 2009 I don't see how you can use verizon's mail server with they require authentication. Link to comment https://forums.phpfreaks.com/topic/154580-sending-email-via-php/#findComment-812869 Share on other sites More sharing options...
rodrigo7x Posted August 13, 2009 Author Share Posted August 13, 2009 HI, no one ever responded but in case anyone looks in this post I wanted to provide the solution that worked for me, I was using the wrong code in php, here it is: <?php require_once("/usr/local/php5/PHPMailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->ContentType = "text/plain"; // text/plain or text/html $mail->Host = "localhost"; // had been hacked in class.smtp.php, ssl://smtp.gmail.com $mail->SMTPAuth = false; $mail->Username = "[email protected]"; $mail->Password = "xxxxx"; $mail->From = "[email protected]"; $mail->FromName = "www.gmail.com"; $mail->AddAddress("[email protected]"); // CC and BCC // $mail->AddCC("[email protected]"); // $mail->AddBCC("[email protected]"); $mail->Subject = "This is my subject"; $mail->Body = "This is my message"; if(!$mail->Send()) { echo "Message was not sent"; echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Email sent"; } ?> Link to comment https://forums.phpfreaks.com/topic/154580-sending-email-via-php/#findComment-897165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.