ChaosKnight Posted May 14, 2010 Share Posted May 14, 2010 This code is supposed to display a form and when the submit button is pressed, include the PEAR Mail package and send an e-mail based upon the results sent back from the form. <?php if (isset($_POST['submit'])){ ini_set( "include_path", ( "public_html/domain/route/pear/PEAR/" . PATH_SEPERATOR . ini_get("include_path") ) ) ); include("db.php"); require_once "mail/Mail.php"; // DB code that works left out... if(mysql_query($sql,$link)){ //PEAR Mailer (Where the problem starts) $from = "From <address>"; $to = "To <address>"; $host = "url"; $username = "username"; $password = "password"; $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, $message); if (PEAR::isError($mail)) { echo "<h3>The message was not sent...</h3>" . $mail->getMessage(); }else{ echo "<h3>The message was sent successfully...</h3>"; } } mysql_close($db_link) } ?> // Form left out because the code is correct When I go to the page, the include isn't displayed, it shows a blank where the form is supposed to be... So I don't even know if the e-mail will send correctly, because I can't submit anything. But when I comment out the include_path, mail functions and the require once, the form displays again, so I think the problem is there somewhere... I uploaded the PEAR Base files to the directory that I used in the include_path function, the pear mail package is also uploaded... I don't know if there are any extra configuration steps that I missed, because this is the very first time that I tried using a PEAR package... I just uploaded everything I thought was necessary. Thanks Link to comment https://forums.phpfreaks.com/topic/201750-pear-mail-package-please-help/ Share on other sites More sharing options...
Deoctor Posted May 15, 2010 Share Posted May 15, 2010 in pear Mail.php will be in the PEAR folder itself. it will not be in the mail/Mail.php so change ur require to require "Mail.php" i didnt checked ur code that much but u try this one.. <?php require_once "Mail.php"; $from = ""; $to = ""; $subject = "Hi!"; $body = "<h1>Hi</h1>,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $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>"); } ?> Link to comment https://forums.phpfreaks.com/topic/201750-pear-mail-package-please-help/#findComment-1058648 Share on other sites More sharing options...
ChaosKnight Posted May 15, 2010 Author Share Posted May 15, 2010 Thanks, but I got it working with PHPMailer, so I decided to continue using it for now... Solved... Link to comment https://forums.phpfreaks.com/topic/201750-pear-mail-package-please-help/#findComment-1058650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.