Jump to content

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

 

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.

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.