0
votes

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 = "[email protected]"; 

$headers["From"]    = "[email protected]"; 
$headers["To"]      = "[email protected]"; 
$headers["Subject"] = "Test message"; 

$body = "TEST MESSAGE!!!"; 

$params["host"] = "smtp.google.com"; 
$params["port"] = "465"; 
$params["auth"] = true; 
$params["username"] = "[email protected]"; 
$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) "[email protected]" ["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) "[email protected]" ["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) "[email protected]" [1]=> array(3) { ["From"]=> string(25) "[email protected]" ["To"]=> string(25) "[email protected]" ["Subject"]=> string(12) "Test message" } [2]=> string(15) "TEST MESSAGE!!!" } } }
  ["callback"]=> NULL
}
1
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 stackoverflow.com/questions/1248952/… for how to disable them. For debugging, simply start with one of the examples at php.net/manual/en/function.mail.php - without using PEAR.Shi
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? Thanksuser1402171
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
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
Erhm… isn't it smtp.gmail.com for Gmail?Shi

1 Answers

1
votes

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