Hello.
I used to make simple php mail form years ago and just got back into webdesign. I thought I would be able to figure this out but I´m clearly missing something. I did not write this code by the way.

I have this html form:

										<div class="row">
											<div class="col-md-6 control-group">
												<div class="alt-placeholder">Name</div>
												<input type="text" name="your-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="your-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="your-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>

And this php-file:

// Change this options:
$username = 'something@gmx.com';
$password = 'password';
$smtpHost = 'ssl://mail.gmx.com';
$smtpPort = '587';
$to = 'something@gmx.com';
$from = 'something@gmx.com';

$subject = 'Contact Form';
$successMessage = 'Message successfully sent!';

$replyTo = $_POST['your-email'];
$name = $_POST['your-name'];
$body = $_POST['your-message'];

$headers = array(
	'From' => $name . " <" . $from . ">",
	'Reply-To' => $name . " <" . $replyTo . ">",
	'To' => $to,
	'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
			'host' => $smtpHost,
			'port' => $smtpPort,
			'auth' => true,
			'username' => $username,
			'password' => $password
		));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
	echo($mail->getMessage());
} else {
	echo($successMessage);
}
?>

I downloaded the Pear Mail Package and uploaded it to the root folder.
I get error messages concerning the Pear-files and I have no clue.

Please. Hope someone can help :-)

    Welcome...I edited your post to replace the single back-tick characters around the code blocks (that unfortunately is ass the </> button does in the edit window) with triple back-ticks, which work much better for code blocks (or you can use [code]...[/code]) tags for the same effect.

    It would help to see the error messages. 🙂

    My guess is some missing step in the PEAR config and/or installation of that specific module, but to be honest I haven't touched PEAR stuff in quite some time (and I've always used PHPMailer when I've needed to do mail stuff).

      Before uploading the package I got this message:

      Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/eterya.com/perfect-nme.com/contact.php on line 27

      Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.') in /var/www/eterya.com/perfect-nme.com/contact.php on line 27

      After the upload I got the same message but regarding another missing file. I removed the package so I don´t remember what file but atleast it recognized the requiered Mail.php.

      To be honest I think I´m going to try edit the form and contact.php to work with PHPMailer and come back here to hopefully tell you that it worked. If not, I´ll ask for help regarding that :-)
      If you have any tips about how to go about using PHPMailer with the form above, it will be greatly appreciated.

      By the way, my web hotel provider seems to to have PHPMailer allready installed.

      Thank you.

      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 :-)