0

I am trying to get php to send a new user an activation email when creating an account. My problem is not with the code for this process, but with php sending out emails.

So far I have install Xampp on Ubuntu server 12.04 with a Kubuntu desktop installed. I have also installed pear using the sudo apt-get install php-pear command.

Finally I installed postfix. When I load my page in the browser I recieve the following errors:

Deprecated: Assigning the return value of new by reference is deprecated in /opt/lampp/lib/php/Mail.php on line 55

Deprecated: Assigning the return value of new by reference is deprecated in /opt/lampp/lib/php/Mail.php on line 135

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /opt/lampp/lib/php/Mail/smtp.php on line 167

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /opt/lampp/lib/php/Net/SMTP.php on line 290

Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in /opt/lampp/lib/php/Mail/smtp.php on line 168

Thanks for your reply! I am still having some problems though Heres my code:

<?php 
include("Mail.php"); 

$recipients = "noreply.njmedia@gmail.com"; 

$headers["From"]    = "noreply.njmedia@gmail.com"; 
$headers["To"]      = "noreply.njmedia@gmail.com"; 
$headers["Subject"] = "Test message"; 

$body = "TEST MESSAGE!!!"; 

$params["host"] = "smtp.google.com"; 
$params["port"] = "465"; 
$params["auth"] = true; 
$params["username"] = "noreply.njmedia@gmail.com"; 
$params["password"] = "gmailpassword(my real password is entered here)"; 

// Create the mail object using the Mail::factory method 
$mail_object =& Mail::factory("smtp", $params); 

$mail_object->send($recipients, $headers, $body); 
?>

Here's the result of the debug:

object(PEAR_Error)#4 (8) {
  ["error_message_prefix"]=> string(0) ""
  ["mode"]=> int(1)
  ["level"]=> int(1024)
  ["code"]=> NULL
  ["message"]=> string(52) "unable to connect to smtp server smtp.google.com:465"
  ["userinfo"]=> NULL
  ["backtrace"]=> array(3) { [0]=> array(6) { ["file"]=> string(27) "/opt/lampp/lib/php/PEAR.php" ["line"]=> int(533) ["function"]=> string(10) "PEAR_Error" ["class"]=> string(10) "PEAR_Error" ["type"]=> string(2) "->" ["args"]=> array(5) { [0]=> string(52) "unable to connect to smtp server smtp.google.com:465" [1]=> NULL [2]=> int(1) [3]=> int(1024) [4]=> NULL } } [1]=> array(7) { ["file"]=> string(32) "/opt/lampp/lib/php/Mail/smtp.php" ["line"]=> int(169) ["function"]=> string(10) "raiseError" ["class"]=> string(4) "PEAR" ["object"]=> object(Mail_smtp)#1 (10) { ["host"]=> string(15) "smtp.google.com" ["port"]=> string(3) "465" ["auth"]=> bool(true) ["username"]=> string(25) "noreply.njmedia@gmail.com" ["password"]=> string(28) "Fakepasswordforstackoverflow" ["localhost"]=> string(9) "localhost" ["timeout"]=> NULL ["verp"]=> bool(false) ["debug"]=> bool(false) ["sep"]=> string(2) " " } ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(52) "unable to connect to smtp server smtp.google.com:465" } } [2]=> array(7) { ["file"]=> string(32) "/media/HDD2/NJmedia/mailtest.php" ["line"]=> int(23) ["function"]=> string(4) "send" ["class"]=> string(9) "Mail_smtp" ["object"]=> object(Mail_smtp)#1 (10) { ["host"]=> string(15) "smtp.google.com" ["port"]=> string(3) "465" ["auth"]=> bool(true) ["username"]=> string(25) "noreply.njmedia@gmail.com" ["password"]=> string(28) "Fakepasswordforstackoverflow" ["localhost"]=> string(9) "localhost" ["timeout"]=> NULL ["verp"]=> bool(false) ["debug"]=> bool(false) ["sep"]=> string(2) " " } ["type"]=> string(2) "->" ["args"]=> array(3) { [0]=> string(25) "noreply.njmedia@gmail.com" [1]=> array(3) { ["From"]=> string(25) "noreply.njmedia@gmail.com" ["To"]=> string(25) "noreply.njmedia@gmail.com" ["Subject"]=> string(12) "Test message" } [2]=> string(15) "TEST MESSAGE!!!" } } }
  ["callback"]=> NULL
}
Community
  • 1
  • 1
user1402171
  • 113
  • 2
  • 7
  • Don't worry about the two deprecated warnings and the strict standards warnings. PEAR is written for PHP prior 5 and running that code in PHP 5 leads to those warnings. See http://stackoverflow.com/questions/1248952/php-5-disable-strict-standards-error for how to disable them. For debugging, simply start with one of the examples at http://php.net/manual/en/function.mail.php - without using PEAR. – Shi Aug 23 '12 at 00:22
  • I added an edit in my question above. I didn't disable the errors, but it should still work right? I refresh the code in my browser yet I never recieve an email in my gmail account. Are there any errors in my code that code be causing this? Thanks – user1402171 Aug 23 '12 at 11:58
  • Try to debug what's going on by checking the return value of `send()` like so: `var_dump($mail_object->send($recipients, $headers, $body));`. – Shi Aug 23 '12 at 20:37
  • I added another edit to my above question. The code is the return value of send like you said. Based on my knowledge it looks like pear was unable to connect to google's smtp servers. Am I correct in that statement? How would you recommend fixing this problem? Thanks :) – user1402171 Aug 23 '12 at 21:49
  • Erhm… isn't it `smtp.gmail.com` for Gmail? – Shi Aug 23 '12 at 21:56
  • I tried it to see if it was, but the page never loads. Could there be a problem with my php.ini file or something of that sort? – user1402171 Aug 23 '12 at 22:27
  • If the page does not load, try to get information from PHP error log or run the script in a PHP debugger. – Shi Aug 25 '12 at 21:03
  • I wasn't having any luck with pear, so I installed msmtp. It sends mail from the terminal fine, but It still doesn't work with the php mail function. Since this kind of changes the focus of this forum question should I start a new forum question? – user1402171 Aug 26 '12 at 19:40

1 Answers1

1

Use the Command : whereis pear

It'll give you the path of pear.

sudo  <the path where Pear is located>  install mail <br/>
sudo  <the path where Pear is located>  install Net_SMTP <br/>
sudo  <the path where Pear is located>  install Auth_SASL <br/>
sudo  <the path where Pear is located>  install mail_mime <br/>

For me it was

sudo /opt/lampp/bin/pear install mail <br/>
sudo /opt/lampp/bin/pear install Net_SMTP <br/>
sudo /opt/lampp/bin/pear install Auth_SASL <br/>
sudo /opt/lampp/bin/pear install mail_mime <br/>

Please restart your XAMP server Using

Start Lampp

sudo /opt/lampp/lampp start

Stop Lampp

sudo /opt/lampp/lampp stop

Thank you

Akos K
  • 7,071
  • 3
  • 33
  • 46