if(isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; require_once('path/to/PHPMailer/PHPMailerAutoload.php'); $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; // Specify SMTP server $mail->SMTPAuth = true; $mail->Username = 'your_email_address@gmail.com'; $mail->Password = 'your_email_password'; $mail->setFrom('from_email@example.com', 'From Name'); $mail->addAddress('to_email@example.com', 'To Name'); $mail->Subject = $subject; $mail->isHTML(true); $mail->Body = 'Name: '.$name.'This code checks if the "submit" button has been clicked and then retrieves the form data using the $_POST superglobal. It then requires the PHPMailerAutoload.php file, sets up the SMTP details and sender/recipient email addresses, sets the email subject and HTML body, and sends the email. If there are any errors, it displays an error message; otherwise, it displays a success message. Overall, using the PHPMailer library makes creating a PHP contact form simple and straightforward.
Email: '.$email.'
Message: '.$message; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } }