Jump to content

Sending Mail - PHP/SMTP/PEAR


m2e

Recommended Posts

Hello,

 

I've recently had to upgrade my sendmail script on my website, due to tighter security. So I now have to use one which uses my SMTP information.  My ISP directed me to a script - but as I have very limited knowledge of PHP - I am having some difficulties with it.

 

The first line of the script is

 

require_once "mail.php";

 

What is mail.php - is this another file somewhere within the PHP installation - or should the file that this code is in be called mail.php?

 

Secondly - what does this require_once actually do? Is it necessary?

 

When I run the script as it is, with this line - I get this error:

 

Warning: main(mail.php) [function.main]: failed to open stream: No such file or directory in /home/rgevans/public_html/event_signup/emailtest.php on line 246

 

Fatal error: main() [function.require]: Failed opening required 'mail.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/rgevans/public_html/event_signup/emailtest.php on line 246

 

When I run the script with require_once edited out I get the following error:

 

Fatal error: Undefined class name 'mail' in /home/rgevans/public_html/event_signup/emailtest.php on line 260

 

The first error would suggest to me that this is a file already installed - the second suggests that this is something created within the code - but again as I said - I'm a novice!

 

My actual code is below:

 

 

<?php
#require_once "mail.php";

$from = "Ment2Excel Guest List <[email protected]>";
$to = $email;
$subject = "Ment2Excel Guest List Registration";
$body = "Hi,\n\nHow are you?";

$host = "mail.XXX.com";
$username = "[email protected]";
$password = "XXXXX";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");
}
?>

 

Thanks in advance for your time.

 

Link to comment
https://forums.phpfreaks.com/topic/133620-sending-mail-phpsmtppear/
Share on other sites

Leave the line intact. If you've been directed to a script then you should've also received a file called mail.php.

The first error is saying that it couldn't find that file 'mail.php', which should be in the same directory as the file that calls mail.php

 

The second error is because, well, mail.php isn't included and it would seem to contain a class called mail, which it cannot use because the file mail.php can't be found.

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.