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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

configuring php5 /php mailer. 1

Status
Not open for further replies.

jlockley

Technical User
Nov 28, 2001
1,522
US
I need to set up PHPMailer on a unix server with Apache2.2, PHP5. I have PHPMailer, but being relatively new to this, I am confused on a couple of points. I am up to my ears in UNIX books and web sites, some of which are terrific, but I am stuck on the simple stuff.


1) Obviously it matters which directory you put it in. One instruction is usr/lib/
Another says place it in your public directory
I /public/Phpmailer/ Does this matter?

2) which raises the question of configuring php.ini
Is it added as an extension, or how is it referenced in the ini file

3) furthermore
What changes need to be made in [mail function] or sendmail path, if any (or does this reference PHPmailer.

I apologize for asking anything so basic, but I am just not finding what I need to know. (also not on the PHPmailer site, which doesn't mean it isn't there.)

 
php mailer is just a set of scripts. it is not an extension.
it does not matter where you put it, so long as your script knows where to find it. You tell your script (typically) by using the include/require functions.
no changes need to be made to php.ini. particularly if you use the smtp functions of phpmailer (which is recommended).
 
Aha! Thanks. As usual looking in all the wrong places.
By script you of course mean the mailing script itself, right?
 
I'd pass a star for that, but I think the question was so obvious, that it would look silly. I have spent days on this.
 
not quite.

assume your main script is in a folder /myfolder and you have stored phpmailer in /usr/local

to bring phpmailer into scope you need to do the following in your /myfolder/index.php script

Code:
require '/usr/local/phmailer.php';
 
Thanks. Am I correct in assuming that index.php is the script I am writing to collect and send information from the form?
(Not something having to do with an array for say an sql database. that is).

And, just to get it straight, PHPmailer does not require that an Include path be set up in PHP.ini, right?



 
Great. Theoretically I am good to go then. Thank you very much.
 
Thanks. I have a few, but I Need to get the script together before I ask more.
 
I am taking you up on the offer. I got in over my head and decided to go back and just try the basic example given at site wizard altered as below.

Does this mean I must have Pear installed? It appears that it was not compiled with PHP on installation. (I did not do this).

sendmail.php as follows (with my site correctly entered)

<?php
require '/usr/lib/PHPMailer.php';
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "me@mysite.com", "Feedback Form Results",
$message, "From: me@mysite.com" );
header( "Location: );
?>


Unfortunately the results I get are: Warning:

require(/usr/lib/PHPMailer.php) [function.require]: failed to open stream: No such file or directory in /var/ on line 2

Fatal error: require() [function.require]: Failed opening required '/usr/lib/PHPMailer.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/ on line 2
 
ok.

the error means that the file PHPMailer.php is not within the directory /usr/lib. it is more usually stored in its own directory, so maybe you want to check the path. and it is usually called class.phpmailer.php too.

secondly, you don't use the mail command with phpmailer. check out the phpmailer examples page for instructions.
 
Well, that's a start. I finally found the PHPMailer documentation, which helps immensely, but I am not home safe yet.

I have tried two scripts, yours from
and one following the PHPmailer instructions. See both below.

The respective errors after the quotes. I have spoken with tech support at ihostexchange which referred me to this:

A previous inquiry said useraccount should be the SAM name (jlockley_myaccou) which brings the same results.

thoughts would be appreciated

<?php
require("/usr/lib/PHPMailer/class.phpmailer.php");

class ihostmailer extends PHPMailer {
/** CHANGE THESE AS REQUIRED **/
public $From = "jlockley@mysite.com";
public $FromName = "me testing"; //PUT YOUR NAME HERE
public $Password = "Mypassw@rd"; //PUT YOUR PASSWORD HERE

/** DO NOT CHANGE THESE **/
public $Host = "ssl://smtp.ihostexchange.net";
public $Mailer = "smtp";
public $WordWrap = 75;
/**I changed this as this is the ihostexchange port**/
public $Port = "587";
public $SMTPAuth = true;


public function __construct($debug = false){
$this->Sender = $this->From;
$this->Username = $this->From;
$this->SMTPDebug = $debug;
}
}

$mail = new ihostmailer(true); //change to true if you are having trouble
$mail->AddAddress('jlockley@mysite.com', 'to me');
$mail->Body = "This is a test message";
$mail->Subject = "Test Message";
if ($mail->send()) {echo "mail sent";};
?>

Produces Error:
SMTP -> ERROR: Failed to connect to server: (0)
SMTP Error: Could not connect to SMTP host.

as does this script:
<?php
require("/usr/lib/PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.ihostexchange.net";
$mail->port = "587";
$mail->auth = "true";
$mail->username = "me@mysite.com";
$mail->password = "password";
$mail->From = "jlockley@mysite.com";
$mail->AddAddress("jlockley@mysite.com.com","to address");
$mail->Subject = "test basic.php";
$mail->Body = "Ha! \n\n I'll believe it when I see it.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
 
your username is not your email address for sherweb. instead the username looks more like this
<stuff before the ampersat>_<bit of the domain name up to 20 chars in total>

you get the name from your sherweb control panel.

my code should work fine when you change the username. not sure about the second as the variable should be Username not the lowercase equivalent.
 
I tried the SAM name. The second tech insisted it was the email address. Will try again, but it did not work the first time. I have another idea. Will report back. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top