www.webdeveloper.com
Results 1 to 9 of 9

Thread: [RESOLVED] Problems with PHPMailer

  1. #1
    Join Date
    Jun 2013
    Posts
    36

    resolved [RESOLVED] Problems with PHPMailer

    Since I couldn't get email to send through PHP via SMTP by making changes to my php.ini and sendmail.ini, I decided to setup PHPMailer.

    After the install, I was able to successfully receive the test mail from PHPMailer BUT I'm not sure what all I need to do to get the email to send properly via my send.php code.

    ** I shouldn't have to have the form setup in the PHPMailer folder to work properly - right?

    My error messages:

    Warning: require(class.phpmailer.php): failed to open stream: No such file or directory in C:\xampp\htdocs\transferform\send.php on line 3

    Fatal error: require(): Failed opening required 'class.phpmailer.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\transferform\send.php on line 3

    Not sure what PEAR has to do with PHPMailer. I have PHPMailer installed in htdocs\PHPMailer

    PHP Code:
    //Top of my send.php code:

    <?php 
    sleep
    (2)/
    require(
    "class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "IP Address"// SMTP server

    //bottom of code:
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers'-f [email]user123@company.com[/email]' ); 
    echo 
    'Thank you, your request has been sent!';    
        
    ?>
    ** I tried to add the following statement
    require("php\PEAR\class.phpmailer.php");

    ** As a test, I copied class.phpmailer.php into my folder that contains my html form and send.php files and I didn't receive any error messages but I also didn't get the email.
    ARRRGGGHHH...


    Thanks

  2. #2
    Join Date
    Mar 2011
    Posts
    1,159
    The error message indicates that the script couldn't locate the 'class.phpmailer.php' file. The easiest solution is to add a complete path to the file using something like:
    Code:
    require('C:\xampp\php\[PATH TO FILE]\class.phpmailer.php');
    A quick browse with Windows Explorer should show the exact path.

  3. #3
    Join Date
    Jun 2013
    Posts
    36

    No Errors now but email not being received

    Quote Originally Posted by rtrethewey View Post
    The error message indicates that the script couldn't locate the 'class.phpmailer.php' file. The easiest solution is to add a complete path to the file using something like:
    Code:
    require('C:\xampp\php\[PATH TO FILE]\class.phpmailer.php');
    A quick browse with Windows Explorer should show the exact path.
    I have the following
    Code:
    require('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');
    I'm not receiving any errors now but email seems to keep going into my Apache/mailoutput folder. This is the same problem I had trying to use SMTP setup through php.ini and sendmail.ini

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,623
    Instead of using PHP's mail(), you would instead use the PHPMailer methods to add recipients, subject, etc., then send() it.

    Check these examples, which should give you what you need. (If not, I'll check back later, but might not be until tonight. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jun 2013
    Posts
    36
    here is my send.php code, notice I changed my require path per your suggestion - I'm not getting any errors and email is sitting in Apache/mailoutput folder.

    PHP Code:
    <?php 
    sleep
    (2)/
    require(
    'C:\xampp\htdocs\PHPMailer\class.phpmailer.php');

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->Host     "ipaddress"// SMTP server

    //Sanitize incoming data and store in variable

    $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        
    $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    
    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    
    $requestedBy trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));
    $requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    
    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    
    $R_branch trim(stripslashes(htmlspecialchars ($_POST['R_branch'])));
    $S_branch trim(stripslashes(htmlspecialchars ($_POST['S_branch'])));

    $R_branch ucfirst(substr($R_branch2));
    $S_branch ucfirst(substr($S_branch2));
        
    // Array for the R_emails option from form
    $R_emails = array(
        
    'R_boston' => 'boston@test.com'
        
    'R_buffalo' => 'buffalo@emailhere.com',
        
    'R_cinncinatti' => 'cinncinatti@email.com'
        
    'R_columbia' => 'columbia@test.com',
        
    'R_dallas' => 'dallas@emailhere.com',  
        
    'R_fairfax' => 'fairfax@emailhere.com'
        
    'R_kansas' => 'kansas@email.com'
        
    'R_la' => 'la@emailhere.com',
        
    'R_orlando' => 'orlando@email.com'
        
    'R_raleigh' => 'raleigh@emailhere.com',
        
    'R_toledo' => 'toledo@emailhere.com',
        
    'R_topeka' => 'topeka@emailhere.com'
    );

    // get receiving email and turn in the the R_email variable
    $R_email $R_email$_POST['R_branch'] ];    

    // Array for the S_emails option from form
    $S_emails = array(
        
    'S_boston' => 'boston@test.com'
        
    'S_buffalo' => 'buffalo@emailhere.com',
        
    'S_cinncinatti' => 'cinncinatti@email.com'
        
    'S_columbia' => 'columbia@test.com',
        
    'S_dallas' => 'dallas@emailhere.com',  
        
    'S_fairfax' => 'fairfax@emailhere.com'
        
    'S_kansas' => 'kansas@email.com'
        
    'S_la' => 'la@emailhere.com',
        
    'S_orlando' => 'orlando@email.com'
        
    'S_raleigh' => 'raleigh@emailhere.com',
        
    'S_toledo' => 'toledo@emailhere.com',
        
    'S_topeka' => 'topeka@emailhere.com'
            
    );

    // get receiving email and turn in the the S_email variable
    $S_email $S_emails$_POST['S_branch'] ];    

    //Prepare information from form to be sent 
    $to 'sparkymom78@gmail.com';
    $from 'sharepoint@company.com';
    $subject 'Online Order Request';
    $headers 'MIME-VERSION: 1.0' '\n';
    $headers .= 'From: $from' '\n';
    "CC: testing123@company.com";
    $body 'Stock Number: ' .$stockNumber PHP_EOL;
    $body .= 'Serial Number: ' .$serialNumber PHP_EOL;
    $body .= 'Description: ' .$description PHP_EOL;
    $body .= 'Requested By: ' .$requestedBy PHP_EOL;
    $body .= 'Requested Date: ' .$requestedDate PHP_EOL;
    $body .= 'Customer Info: ' .$customerInfo PHP_EOL;

    // Form data was successful so we will now send admin email and return message to the user
    $success mailimplode(',', array( $R_email$S_email )), $subject$body$headers '-f user123@company.com' ); 
    echo 
    'Thank you, your request has been sent!';    

    ?>

  6. #6
    Join Date
    Mar 2011
    Posts
    1,159
    Oh, I forgot that I had seen you discussing this before. I did a little research but didn't get back here.

    The real issue is that there is no mail server on your computer to actually send the Emails. There are a variety of solutions and possible work-arounds. Try searching on "windows mail server freeware" and you'll find some good information.

  7. #7
    Join Date
    Jun 2013
    Posts
    36
    Thanks for the help! I'm posting the final output to share with everyone because I could not find a good inclusive set of code anywhere to help me out. This has been a huge project with an HTML form, posting to send.php (which is attached below) using PHPMailer. I hope this helps someone else in the future.




    PHP Code:
     <?php sleep(2);require('../PHPMailer/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();  // telling the class to use SMTP$mail->Host     = "ip address"; // SMTP server
    //Sanitize incoming data and store in variable $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    $requestedBy = trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));$requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    $R_branch = trim(stripslashes(htmlspecialchars ($_POST['R_branch'])));$S_branch = trim(stripslashes(htmlspecialchars ($_POST['S_branch'])));
    $R_branch ucfirst(substr($R_branch2));  // removes the R_ and capitalizes first letter of branch in final output to email$S_branch = ucfirst(substr($S_branch, 2));  // removes the S_ and capitalizes first letter of branch in final output to email    
    // Array for the R_emails option from form$R_emails = array(    'R_boston' => 'boston@test.com',     'R_buffalo' => 'buffalo@emailhere.com',    'R_cinncinatti' => 'cinncinatti@email.com',     'R_columbia' => 'columbia@test.com',    'R_dallas' => 'dallas@emailhere.com',      'R_fairfax' => 'fairfax@emailhere.com',     'R_kansas' => 'kansas@email.com',     'R_la' => 'la@emailhere.com',    'R_orlando' => 'orlando@email.com',     'R_raleigh' => 'raleigh@emailhere.com',    'R_toledo' => 'toledo@emailhere.com',    'R_topeka' => 'topeka@emailhere.com', );
    // get receiving email and turn in the the R_email variable$R_email = $R_email[ $_POST['R_branch'] ];    
    // Array for the S_emails option from form$S_emails = array(    'S_boston' => 'boston@test.com',     'S_buffalo' => 'buffalo@emailhere.com',    'S_cinncinatti' => 'cinncinatti@email.com',     'S_columbia' => 'columbia@test.com',    'S_dallas' => 'dallas@emailhere.com',      'S_fairfax' => 'fairfax@emailhere.com',     'S_kansas' => 'kansas@email.com',     'S_la' => 'la@emailhere.com',    'S_orlando' => 'orlando@email.com',     'S_raleigh' => 'raleigh@emailhere.com',    'S_toledo' => 'toledo@emailhere.com',    'S_topeka' => 'topeka@emailhere.com',       );
    // get receiving email and turn in the the S_email variable$S_email = $S_email[ $_POST['S_branch'] ];     //Prepare information from form to be sent $body = 'Stock Number: ' .$stockNumber . PHP_EOL;$body .= 'Serial Number: ' .$serialNumber . PHP_EOL;$body .= 'Description: ' .$description . PHP_EOL;$body .= 'Requested By: ' .$requestedBy . PHP_EOL;$body .= 'Requested Date: ' .$requestedDate . PHP_EOL;$body .= 'Customer Info: ' .$customerInfo . PHP_EOL;$body .= 'Requesting Branch: ' .$R_branch . PHP_EOL;$body .= 'Shipping Branch: ' .$S_branch . PHP_EOL; // Form data was successful so we will now send admin email and return message to the user$mail = new PHPMailer(); $mail->IsSMTP();$mail->Host     = "ip address"; 
    $mail->From     "sharepoint@company.com";$mail->FromName "Excited";$mail->AddAddress($R_email'R_branch');$mail->AddAddress($S_email'S_branch');$mail->AddCC("user345@company.com"); $mail->Subject  "Order Request Form";$mail->Body     $body;$mail->WordWrap 50; if(!$mail->Send()) {  echo 'Message was not sent.';  echo 'Mailer error: ' $mail->ErrorInfo;} else {  echo 'Thank you, your request has been sent!';}    ?>

  8. #8
    Join Date
    Jun 2013
    Posts
    36
    Sorry last code was messed up, wish I could edit on here.

    PHP Code:

    <?php sleep(2);require('../PHPMailer/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();  // telling the class to use SMTP$mail->Host     = "ip address"; // SMTP server
    //Sanitize incoming data and store in variable $stockNumber =  trim(stripslashes(htmlspecialchars ($_POST['stockNumber'])));        $serialNumber =  trim(stripslashes(htmlspecialchars ($_POST['serialNumber'])));    $description =  trim(stripslashes(htmlspecialchars ($_POST['description'])));    $requestedBy = trim(stripslashes(htmlspecialchars ($_POST['requestedBy'])));$requestedDate =  trim(stripslashes(htmlspecialchars ($_POST['requestedDate'])));    $customerInfo =  trim(stripslashes(htmlspecialchars ($_POST['customerInfo'])));    $R_branch = trim(stripslashes(htmlspecialchars ($_POST['R_branch'])));$S_branch = trim(stripslashes(htmlspecialchars ($_POST['S_branch'])));
    $R_branch ucfirst(substr($R_branch2));  // removes the R_ and capitalizes first letter of branch in final output to email$S_branch = ucfirst(substr($S_branch, 2));  // removes the S_ and capitalizes first letter of branch in final output to email    
    // Array for the R_emails option from form$R_emails = array(    'R_boston' => 'boston@test.com',     'R_buffalo' => 'buffalo@emailhere.com',    'R_cinncinatti' => 'cinncinatti@email.com',     'R_columbia' => 'columbia@test.com',    'R_dallas' => 'dallas@emailhere.com',      'R_fairfax' => 'fairfax@emailhere.com',     'R_kansas' => 'kansas@email.com',     'R_la' => 'la@emailhere.com',    'R_orlando' => 'orlando@email.com',     'R_raleigh' => 'raleigh@emailhere.com',    'R_toledo' => 'toledo@emailhere.com',    'R_topeka' => 'topeka@emailhere.com', );
    // get receiving email and turn in the the R_email variable$R_email = $R_email[ $_POST['R_branch'] ];    
    // Array for the S_emails option from form$S_emails = array(    'S_boston' => 'boston@test.com',     'S_buffalo' => 'buffalo@emailhere.com',    'S_cinncinatti' => 'cinncinatti@email.com',     'S_columbia' => 'columbia@test.com',    'S_dallas' => 'dallas@emailhere.com',      'S_fairfax' => 'fairfax@emailhere.com',     'S_kansas' => 'kansas@email.com',     'S_la' => 'la@emailhere.com',    'S_orlando' => 'orlando@email.com',     'S_raleigh' => 'raleigh@emailhere.com',    'S_toledo' => 'toledo@emailhere.com',    'S_topeka' => 'topeka@emailhere.com',       );
    // get receiving email and turn in the the S_email variable$S_email = $S_email[ $_POST['S_branch'] ];     //Prepare information from form to be sent $body = 'Stock Number: ' .$stockNumber . PHP_EOL;$body .= 'Serial Number: ' .$serialNumber . PHP_EOL;$body .= 'Description: ' .$description . PHP_EOL;$body .= 'Requested By: ' .$requestedBy . PHP_EOL;$body .= 'Requested Date: ' .$requestedDate . PHP_EOL;$body .= 'Customer Info: ' .$customerInfo . PHP_EOL;$body .= 'Requesting Branch: ' .$R_branch . PHP_EOL;$body .= 'Shipping Branch: ' .$S_branch . PHP_EOL; // Form data was successful so we will now send admin email and return message to the user$mail = new PHPMailer(); $mail->IsSMTP();$mail->Host     = "ip address"; 
    $mail->From     "sharepoint@company.com";$mail->FromName "Excited";$mail->AddAddress($R_email'R_branch');$mail->AddAddress($S_email'S_branch');$mail->AddCC("user345@company.com"); $mail->Subject  "Order Request Form";$mail->Body     $body;$mail->WordWrap 50; if(!$mail->Send()) {  echo 'Message was not sent.';  echo 'Mailer error: ' $mail->ErrorInfo;} else {  echo 'Thank you, your request has been sent!';}    ?>

  9. #9
    Join Date
    Jun 2013
    Posts
    36
    beginning code:

    <?php
    sleep(2);
    require('../PHPMailer/class.phpmailer.php');


    $mail = new PHPMailer();


    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "ip address"; // SMTP server

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles