ramu321 Posted July 7, 2011 Share Posted July 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/ Share on other sites More sharing options...
gizmola Posted July 7, 2011 Share Posted July 7, 2011 Seems pretty clear that the script needs to include Mail.php, but can not find it for some reason. Is there a script named Mail.php in the same directory as this script? Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239479 Share on other sites More sharing options...
ramu321 Posted July 8, 2011 Author Share Posted July 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239879 Share on other sites More sharing options...
xyph Posted July 8, 2011 Share Posted July 8, 2011 No, but you should include it using the correct path include('/usr/share/psa-pear/Mail.php'); Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239882 Share on other sites More sharing options...
gizmola Posted July 8, 2011 Share Posted July 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239891 Share on other sites More sharing options...
ramu321 Posted July 8, 2011 Author Share Posted July 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239912 Share on other sites More sharing options...
gizmola Posted July 8, 2011 Share Posted July 8, 2011 Yes, looks like safe mode is turned out on your server. Is this shared hosting? Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239934 Share on other sites More sharing options...
ramu321 Posted July 8, 2011 Author Share Posted July 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239940 Share on other sites More sharing options...
gizmola Posted July 8, 2011 Share Posted July 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241300-problem-sending-mail-using-gmail-smtp/#findComment-1239942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.