provider seems to to have PHPMailer allready installed

In that case I'd check their support resources. I'd suspect that the path to the required files is different that the location/path your code has been told to look for.

Ronny

After the upload I got the same message but regarding another missing file.

I don't see any require_once statements in your code here, so it's hard to be sure what the real problem is. I'm guessing you have something like

require_once 'Mail.php';

In order to require a file, you have to be aware of a few contepts.

First, the current working directory. Every time some PHP code executes, some file system path is assumed as the current working directory. You can check this with getcwd. If the file Mail.php is in the current working directory, then requiring it should work. Note that some scripts might alter the current working directory with commands like chdir.

Second, there's the include_path. When PHP runs a script, this determines where PHP will look if you require or include some file. You can check what it is with get_include_path. It may contain more than one path separated by some separator. On linux machines, the separator is a colon. PHP will check each directory in turn when you include or require a file. On my machine right now I get this:

php -r 'echo get_include_path();'
.:/usr/share/php

the . refers to the current working directory. /usr/share/php is a place where all kinds of libs get installed, like PEAR and PHPUnit and stuff. Note that the include_path might differ between your web server and your command line, or even between different users. If you plan to use PEAR packages, you'll probably need to make sure the PEAR directory is one of the directories in your include_path.

Thirdly, PEAR packages often depend on other PEAR packages. If you were seeing a complaint about some package not being installed, you might try including/requiring that one, too.

Rather than downloading the pear files to your 'root' directory (not sure what you mean by that), you might try something like:

$path = '/usr/share/php/PEAR'; // this should be the path where PEAR is installed in your machine
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

dalecosp Thanks for the tip. But Ivé moved on to PHPMailer. Made more sence to me as I´m quite rusty. More rusty than I knew :-D

    Thank you guys for the responses. It´s really heartwarming!!! Great Forum!
    I´ve been busy with other things for the last week but I´m beginning to get the PHPMailer. Seems to be the thing for me. I´ll get back to you with questions about that soon.

      sneakyimp It´s above the code I posted. Didn´t include it it seems. I have however abanded it and is going for PHPMailer for this project. But I really appreciate your post as it clearifies a few things. Been away for a few years and it feels like I´m starting on new :-D
      Thanks man!

        4 days later

        OK. So I´m back 😃 I´m trying out the PHPMailer. I´ve uploaded the files and created a file called "send.php".
        I execute the file in the browser to see if it works before I go any further. I then get this message:

        2022-07-05 20:50:04 SERVER -> CLIENT: 220 websmtp.simply.com ready. Authentication required.
        2022-07-05 20:50:04 CLIENT -> SERVER: EHLO perfect-nme.com
        2022-07-05 20:50:04 SERVER -> CLIENT: 250-websmtp.simply.com250-PIPELINING250-SIZE250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN CRAM-MD5250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
        2022-07-05 20:50:04 CLIENT -> SERVER: STARTTLS
        2022-07-05 20:50:04 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
        2022-07-05 20:50:04 CLIENT -> SERVER: EHLO perfect-nme.com
        2022-07-05 20:50:04 SERVER -> CLIENT: 250-websmtp.simply.com250-PIPELINING250-SIZE250-ETRN250-AUTH PLAIN LOGIN CRAM-MD5250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
        2022-07-05 20:50:04 CLIENT -> SERVER: AUTH CRAM-MD5
        2022-07-05 20:50:04 SERVER -> CLIENT: 334 PDU1MTY0MzEzMzgyNDk5NzkuMTY1NzA1NDIwNEBhc210cC51bm9ldXJvLmNvbT4=
        2022-07-05 20:50:04 CLIENT -> SERVER: [credentials hidden]
        2022-07-05 20:50:06 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: PDU1MTY0MzEzMzgyNDk5NzkuMTY1NzA1NDIwNEBhc210cC51bm9ldXJvLmNvbT4= - For help see https://simply.com/support/?s=websmtp.simply.com
        2022-07-05 20:50:06 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: PDU1MTY0MzEzMzgyNDk5NzkuMTY1NzA1NDIwNEBhc210cC51bm9ldXJvLmNvbT4= - For help see https://simply.com/support/?s=websmtp.simply.com
        SMTP Error: Could not authenticate.
        2022-07-05 20:50:06 CLIENT -> SERVER: QUIT
        2022-07-05 20:50:06 SERVER -> CLIENT: 221 2.0.0 Bye
        SMTP Error: Could not authenticate.
        Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

        Here´s the send.php:

        <?php
        //Import PHPMailer classes into the global namespace
        //These must be at the top of your script, not inside a function
        use PHPMailer\PHPMailer\PHPMailer;
        use PHPMailer\PHPMailer\SMTP;
        use PHPMailer\PHPMailer\Exception;
        
        require 'src/Exception.php';
        require 'src/PHPMailer.php';
        require 'src/SMTP.php';
        
        
        //Create an instance; passing `true` enables exceptions
        $mail = new PHPMailer(true);
        
        try {
            //Server settings
            $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = 'websmtp.simply.com';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = myemail@hello.com';                     //SMTP username
            $mail->Password   = 'Spassword';                               //SMTP password
            $mail->SMTPSecure = 'TLS';            //Enable implicit TLS encryption
            $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
        
            //Recipients
            $mail->setFrom('myemail@hello.com', 'Test');
            $mail->addAddress('myemail@hello.com', 'Joe User');     //Add a recipient
           
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'PERFECT NME - Contact';
            $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
        
            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }

        The authentication username and password is my e-mail account right? God, it´s been a while 😃
        Hope you guys can help.

          Did you leave out the opening quote on this line, or was it just dropped when copied/pasted/edited it here?

          $mail->Username   = myemail@hello.com';
          //                  ^

          PS: Are you sure the port number is correct for that email SMTP service?

          NogDog I missed it as I copied in the fake email address for the post. I´ts all there in the original file. As to the port, it´s 587 according to my mailserver provider.

            My God, this is embarrassing. I act $mail->AltBody = 'We recieved your e-mail. Thank you for contacting us. We will get back to you as soon as possible. Sincerely, PERFECT NME';

            So... I mange to get the confirmation e-mail as a user, but do not get the mail as the recevier. No error messages, just an empty mailbox. Any thoghts? Including the latest version of the send.php. And I have no idea how that smileyface got in there :-D

            <?php
            //Import PHPMailer classes into the global namespace
            //These must be at the top of your script, not inside a function
            use PHPMailer\PHPMailer\PHPMailer;
            use PHPMailer\PHPMailer\SMTP;
            use PHPMailer\PHPMailer\Exception;
            
            require 'src/Exception.php';
            require 'src/PHPMailer.php';
            require 'src/SMTP.php';
            
            $name = $POST['name'];
            $email = $POST['email'];
            
            //Create an instance; passing true enables exceptions
            $mail = new PHPMailer(true);
            
            try {
            //Server settings
            //$mail->SMTPDebug = SMTP:😃EBUG_SERVER; //Enable verbose debug output
            $mail->isSMTP(); //Send using SMTP
            $mail->Host = 'websmtp.simply.com'; //Set the SMTP server to send through
            $mail->SMTPAuth = true; //Enable SMTP authentication
            $mail->Username = 'XXXX@XX.com'; //SMTP username
            $mail->Password = 'XXXXXXXX'; //SMTP password
            $mail->SMTPSecure = 'TLS'; //Enable implicit TLS encryption
            $mail->Port = 587; //TCP port to connect to; use 587 if you have set SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS
            
            //Recipients
            $mail->setFrom('ronny@xxxx.com', 'PERFECT NME');
            $mail->addAddress($email, $name);     //Add a recipient
            //$mail->addAddress('ellen@example.com');               //Name is optional
            //$mail->addReplyTo('info@example.com', 'Information');
            //$mail->addCC('cc@example.com');
            //$mail->addBCC('bcc@example.com');
            
            //Attachments
            //$mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
            //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name
            
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'PERFECT NME - Confirmation';
            $mail->Body    = 'We recieved your e-mail. Thank you for contacting us. We will get back to you as soon as possible.<br><br>Sincerely<br><b>PERFECT NME</b>';
            $mail->AltBody = 'We recieved your e-mail. Thank you for contacting us. We will get back to you as soon as possible. Sincerely, PERFECT NME';
            
            $mail->send();
            echo 'Message has been sent';
            } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
            }

              Did you check your spam folder? (Just in case, before assuming something went wrong with sending it)

                Nothing in my spam folder, I´m afraid :-/

                  Ok. this is starting to bug me out! Is there a possibillety that this is a securety issue with my email provider? Some setting on the backend or wathever since the confirmation-mail from the user shows up? Ivé googled my ass off and cannot find anyone having this issue. At the same time I´ve looked at so many examples of the php-contact files without finding an explanation for my issue. Why do the sender get a confirmation and reciever get nothing?
                  I´ve edited the the code somwhat during this, so if anyone would like to help I will post the code again :-)

                    Glancing through your latest code, it looks to me like this is the only email that would receive anything:

                    $mail->addAddress($email, $name);     //Add a recipient
                    

                    If you're saying that whoever is $email is receiving it but someone else is not, then you probably just need to add another addAddress() for "someone else" (or addCC() or addBCC() if more applicable).

                    NogDog Thanks. That makes sence. Somhow I thougt
                    $mail->setFrom('ronny@xxxx.com', 'PERFECT NME');
                    was the recipiant of the form. Did not occur to me that turorial I followed was just about the confirmation email.
                    I´ll look in to this.

                      I have abandoned the PHPMailer and started over with a simple php mail form. I am now recieving the e-mail but for some reason the input field for ""name" doesn´t show up in the recieved e-mail (The others show up). It sais "Name:" but then it´s blank.
                      Posting the html and php and hoping someone sees what I´m missing.

                      <form class="ajax-form" data-message-class="colors-e background-95 border heading" action="contact-form-handler.php" method="post" novalidate="novalidate">
                      										<div class="row">
                      											<div class="col-md-6 control-group">
                      												<div class="alt-placeholder">Name</div>
                      												<input type="text" name="name" value="" size="40" placeholder="Name" data-validation-required-message="Please fill the required field." required>
                      												<div class="help-block"></div>
                      											</div>
                      											<div class="col-md-6 control-group">
                      												<div class="alt-placeholder">Email</div>
                      												<input type="email" name="email" value="" size="40" placeholder="Email" data-validation-required-message="Please fill the required field." required>
                      												<div class="help-block"></div>
                      											</div>
                      											<div class="col-md-12 control-group">
                      												<div class="alt-placeholder">Message</div>
                      												<textarea name="message" placeholder="Message" data-validation-required-message="Please fill the required field." required></textarea>
                      												<div class="help-block"></div>
                      											</div>
                      											<div class="col-md-12 form-actions">
                      												<input class="button" type="submit" value="Send">
                      												
                      											
                      											</div>
                      										</div>
                      									</form>
                      <?php 
                      
                      $myemail = 'contact@perfect-nme.com';//<-----Put Your email address here.
                      if(empty($_POST['name'])  || 
                         empty($_POST['email']) || 
                         empty($_POST['message']))
                      
                      
                      $name = $_POST['name']; 
                      $email_address = $_POST['email']; 
                      $message = $_POST['message']; 
                      
                      $successMessage = 'Message successfully sent!';
                      
                      
                      {
                      	$to = $myemail; 
                      	$email_subject = "PNME Contact Form: $name";
                      	$email_body = "You have received a new message. ".
                      	" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
                      	
                      	$headers = "From: $myemail\n"; 
                      	$headers .= "Reply-To: $email_address";
                      	
                      	mail($to,$email_subject,$email_body,$headers);
                      	
                      } 
                       
                      	echo($successMessage);
                      
                      
                      
                      ?>

                        The posted php code is only assigning $name = $_POST['name'] IF one or more of the inputs is empty, because there's no {} around any code immediately following that conditional test and the purpose of those empty() tests was (probably) to setup a message if a 'required' input is empty, not to run the form processing code.

                        Post method form processing code should -

                        1. Be on the same page as the form, so that you can populate the form field values with the existing data upon an error, when you display the errors and redisplay the form.
                        2. Detect if a post method form was submitted before referencing any of the form data.
                        3. Keep the form data as a set in an array variable, the use elements in this array variable through the rest of the code.
                        4. Trim all the input data at once (you can do this with one single php statement.)
                        5. Validate all inputs, storing validation errors in an array using the field name as the array index.
                        6. If there are no error after the end of the validation logic (the array holding the errors will be empty), use the submitted form data.
                        7. Do not copy variables to other variables for nothing. This is just a waste of your time typing.
                        8. Do not put external, unknown, dynamic values into the Subject parameter, e.g. the $name.
                        9. Apply htmlentities() to any value being used in a html context to help prevent cross site scripting when the email are read using a browser.
                        10. Validate the format of the submitted email address before using it to insure it only consists of exactly and only one properly formatted email address to prevent mail header injection.
                        11. You must test for a true value returned from the mail() call to decide if the success message should be setup and displayed. For a false value, you should LOG the data so that you will both know that emails are failing and so that you can see if anything about the data is causing the failure.
                        12. Upon successful completion of the form processing code, you should redirect to the exact same url of the current page to cause a get request for that page. This will prevent the browser from trying to resubmit the form data should the page get reloaded or the visitor browses away from and back to the page.
                        13. If you want to display a one time success message, store it in a session variable, the test, display, and clear that session variable at the appropriate location in the html document.

                        pbismad Thank you! That was it. Allso thank you for the list. That was very informative!

                          Write a Reply...