I am newbie and i'm trying to send mail using php but unable to send mail when i click on submit button new window open which contain some part of my php code......i want to send email from user email id to my email id with the content of form

This is the first time i'm using php and i stuck in this

<?php require 'PHPMailerAutoload.php'; require 'class.phpmailer.php'; require 'class.smtp.php'; // require 'class.phpmailer.php'; $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPDebug = 1; $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = "[email protected]"; $mail->Password = "example"; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->From = "[email protected]"; $mail->FromName = "ADMIN"; $mail->addAddress("[email protected]", "User 1"); $mail->IsHTML(true); $mail->Subject = "form Submission"; $subject = $_POST['subject']; $email = $_POST['email']; $phone = $_POST['phone']; $name = $_POST['name']; $company = $_POST['company']; $city = $_POST['city']; $message = $_POST['message']; $mail->Body = " <html> <h2><br>Name: $name</br> <br> Email: $email</br> <br> Phone: $phone</br> <br> Subject: $subject</br> <br> Company: $company</br> <br> City: $city</br> <br> Message: $message </br></h2> </html>"; $mail->AltBody = ''; if (! $mail->Send()) echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo; else echo "Message has been sent"; ?> 

html--> action=""

please help me to resolve this problem

i'm using tomcat server 9.0

my entire php code got print i think php code is not executing

in my webcontent i added

class.smtp.php

class.phpmailer.php

class.PHPMailerAutoload.php

12

2 Answers

<?php include "PHPMailer_5.2.4/class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "[email protected]"; $mail->Password = "test@12#"; $mail->AddReplyTo("[email protected]", "test mail"); $mail->AddAddress('[email protected]', 'test mail '); $mail->Body = "message:hiii"; if ($mail->send()) //if (mail($subject,$message, $headers)) { echo "Thank you for sending mail us!"; } else { echo "Mailed Error: " . $mail->ErrorInfo; } ?> 

this is the sample code..you can download smtp library function from github....

12
<?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\Exception; //Load composer's autoloader require 'vendor/autoload.php'; $mail = new PHPMailer(true); // Passing `true` enables exceptions try { //Server settings $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers (smtp.gmail.com if you can use Gmail Account) $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('[email protected]', 'Mailer'); $mail->addAddress('[email protected]', 'Joe User'); // Add a recipient $mail->addAddress('[email protected]'); // Name is optional $mail->addReplyTo('[email protected]', 'Information'); $mail->addCC('[email protected]'); $mail->addBCC('[email protected]'); //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 = 'Here is the subject'; $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.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } 

Use this configuration and download PHPMailer from GitHub.