Jump to content

Problem sending mail using gmail smtp


ramu321

Recommended Posts

I am new to php, i am trying to configure gmail as smtp and i trying to use php mail pear packages to send mail.

I am getting following error message. Somehow the pear packages are not included to my domain.

 

Warning: include(Mail.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/testmail.php on line 3

 

Warning: include() [function.include]: Failed opening 'Mail.php' for inclusion (include_path='/var/www/vhosts/example.com/httpdocs/:/usr/share/psa-pear/') in /var/www/vhosts/example.com/httpdocs/testmail.php on line 3

 

Fatal error: Class 'Mail' not found in /var/www/vhosts/example.com/httpdocs/testmail.php on line 17

 

 

Code:

<?php

ini_set('display_errors','on');

include("Mail.php");

/* mail setup recipients, subject etc */

$recipients = "[email protected]";

$headers["From"] = "[email protected]";

$headers["To"] = "[email protected]";

$headers["Subject"] = "User feedback";

$mailmsg = "Hello, This is a test.";

/* SMTP server name, port, user/passwd */

$smtpinfo["host"] = "ssl://smtp.gmail.com";

$smtpinfo["port"] = "465";

$smtpinfo["auth"] = true;

$smtpinfo["username"] = "[email protected]";

$smtpinfo["password"] = "password";

/* Create the mail object using the Mail::factory method */

$mail_object = Mail::factory("smtp", $smtpinfo);

/* Ok send mail */

//$mail_object->send($recipients, $headers, $mailmsg);

if (PEAR::isError($mail_object)) {

    echo("<p>" . $mail_object->getMessage() . "</p>");

  }

?>

I really appreciate any help on this.

 

Thanks

-Ramu

Link to comment
https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/
Share on other sites

No, but you should include it using the correct path

 

include('/usr/share/psa-pear/Mail.php');

 

The include family of functions (include/require/require_once) all work with file system paths.  So you have the option of doing one of 3 things:

 

-Use the full path to the file (as xyph suggested)

-Use a relative path  (for example, you had a lib directory where the file was, you could specify 'lib/Mail.php'

-Or there is the php include path. If your script is in a directory in the include path php will find it there.  Typically scripts that are obtained through pear will be in the include path, so if this is where you got the Mail library, that is something you might want to check in your configuration.

Thanks for quick response. I have added following statement

include('/usr/share/psa-pear/Mail.php');

 

Here is error message, am i missing basic thing here?

Warning: include() [function.include]: SAFE MODE Restriction in effect. The script whose uid is 10021 is not allowed to access /usr/share/psa-pear/Mail.php owned by uid 0 in /var/www/vhosts/example.com/httpdocs/testmail.php on line 3

 

Warning: include(/usr/share/psa-pear/Mail.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/testmail.php on line 3

 

Warning: include() [function.include]: Failed opening '/usr/share/psa-pear/Mail.php' for inclusion (include_path='/var/www/vhosts/example.com/httpdocs/:/usr/share/psa-pear/') in /var/www/vhosts/example.com/httpdocs/testmail.php on line 3

 

Fatal error: Class 'Mail' not found in /var/www/vhosts/example.com/httpdocs/testmail.php on line 17

 

Thanks

-Ramu

Great. Yes safe mode is a giant pain in the butt, and definately not needed for your own server.  Its features were designed to try and add controls for shared hosting, but the php project people have pretty much admitted that the features weren't well designed and plan to remove them entirely.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.