Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Mail - PHP/SMTP/PEAR

Status
Not open for further replies.

RussellNiiOdartei

IS-IT--Management
Nov 20, 2008
4
GB
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

Code:
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:

Code:
<?php
#require_once "mail.php";

$from = "Ment2Excel Guest List <guestlist@ment2excel.com>";
$to = $email;
$subject = "Ment2Excel Guest List Registration";
$body = "Hi,\n\nHow are you?";

$host = "mail.XXX.com";
$username = "test@XXX.com";
$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
 
the require_once statement is the best way to include a file (once). You were also sent a file called mail.php, which should be in the same directory or in the configured search path. The file mail.php should contain a definition for the mail class.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top