Jump to content

PHP Pear Mail issue


immodium

Recommended Posts

Hello all.

 

I'm trying to send emails using the following code

 

<?php
require_once "Mail.php";

/**************************************************
EDIT the following variables for your own use
***************************************************/
$from = "Sender <[email protected]>";
$to = "Recipient <[email protected]>";

$subject = "Hi!"; //type in subject here

$host = "mail.example.com"; // Your domain
$username = "smtp_username"; // Your user / full email address
$password = "smtp_password"; // Password to your email address



/**************************************************
***************************************************/

$body = "";

foreach($_POST as $a => $b)
{
$body .= $a .": ". $b . "\n";
}

$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)) {
/**************************************************
ERROR MESSAGE
***************************************************/
?>

<p> <? echo $mail->getMessage(); ?> </p>
<?
/**************************************************/
} else {
/**************************************************
SUCCESS MESSAGE
***************************************************/
?>
<p>Message successfully sent!</p>
<?
/**************************************************/
}
?>

 

I have replaced the information needed with my own (host, username, password, emails, etc) but when I run the script I'm presented with a blank browser.

 

Any ideas why?

 

the mail.php is in my include path. I have changed the smtp details in the php.ini. i'm running this on my localhost. Using apache also if thats relevant.

 

Thanks in advance

 

(I've been away from php now for 8 years. getting back into it never remember having this much problems with windows 98)

Link to comment
https://forums.phpfreaks.com/topic/196514-php-pear-mail-issue/
Share on other sites

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.