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 = "info@example.com";

$headers["From"] = "admin@example.com";

$headers["To"] = "info@example.com";

$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"] = "admin@example.com";

$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
Share on other sites

Thanks for your response gizmola,

 

I have Mail.php in /usr/share/psa-pear/ and i don't have Mail.php in /var/www/vhosts/example.com/httpdocs/

 

Do i have to have the file in /var/www/vhosts/example.com/httpdocs/ ???

 

Thanks

-Ramu

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Wow! it worked now.

 

Thanks a lot for your support.

 

BTW I have turned off SAFE MODE option from my plesk (my domain -> Web hosting settings -> PHP support (unchecked safe mode)

 

Thanks once again

-Ramu

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.