PHP mailer not validating after sending a second email - php

This is an updated msg's with a working code for sending two different emails using php mailer. It also has working validation server site.
You need to create you own mail class or use the normal one.
Hope someone else can use it two!
Thank you!!
<?php
require"validation.php";
ob_start();
$name = trim($_POST['name']);
$email = $_POST['email'];
$comments = $_POST['comments'];
$info_email= 'example#example.com';
$info_name = 'Example';
require"PHPMailer/mail.inc.php";
$cams="$name has just made a comment or posted a question";
$camb= "<html>
<head>
<h3> $name has asked the following question or comment on you website:</h3>
</head>
<body>
$comments <br><br><br>
Their information: <br><br>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\">
<tr>
<td align=\"center\">Name:</td>
<td align=\"center\"> $name</td>
</tr>
<tr>
<td align=\"center\">Email:</td>
<td align=\"center\"> $email</td>
</tr>
</table>
<br>
<img src=\"cid:mailhead\" alt=\"shop logo used in emails\" />
Pleasy try to reply as soon as possible.<br>
Thank you!!
</body>
</html>";
$mail = new MailCon;
$mail->IsSMTP();
$mail->isHTML(true);
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($info_email, $info_name);
$mail->Subject = $cams;
$mail->MsgHTML($camb);
if ($mail->Send()) {
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->ClearCustomHeaders();
$cums = 'Thank you for using our contact form.';
$message = file_get_contents('mail/example.html');
$message = str_replace('%username%', $name, $message);
$message = str_replace('%email%', $email, $message);
$message = str_replace('%comments%', $comments, $message);
$alt_body="Thank you for asking us a question or making a comment. We will reply as soon as possible.";
$mail = new MailCon;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->From = $info_email;
$mail->FromName = $info_name;
$mail->AddAddress($email, $name); // Add a recipient
$mail->Subject = $cums;
$mail->MsgHTML($message);
$mail->AltBody = $alt_body;
$mail->Send();
}
ob_end_flush();
?>
This is the validation bit wich you can include using require once.
<?php
$name = trim($_POST['name']);
$email = $_POST['email'];
$comments = $_POST['comments'];
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 3) {
$error['comments'] = "Please leave a comment.";
}
if (!$error) {
echo "<div class='alert-box success'>Thanks " . $name . ". Your message has been sent.<a href='' class='close' onclick='clearForms()'>×</a></div>";
} # end if no error
else {
$response = (isset($error['name'])) ? "<div class='alert-box alert'>" . $error['name'] . "</div> \n" : null;
$response .= (isset($error['email'])) ? "<div class='alert-box alert'>" . $error['email'] . "</div> \n" : null;
$response .= (isset($error['comments'])) ? "<div class='alert-box alert'>" . $error['comments'] . "</div>" : null;
echo $response;
exit();
} # end if there was an error sending
?>

Related

How to Display Toast Notification in PHP when Form is submitted and went to new URL

on my page when the user submits a form it sends details to my email and went to a new URL.
after the user went t the new URL I want there to show the user about that form that your form is submitted in a toast notification
PHP script for form send via email is this
<?php
if (isset($_POST["sendmessage"])) {
$fname = $_POST["fullname"];
$fnumber = $_POST["phonenumber"];
$femail = $_POST["fullemail"];
$fsubject = $_POST["fullsubject"];
$fmessage = $_POST["fullmessage"];
$status = "";
$subject = "Contact Form | MAKT Website";
$body =
'<p style="font-size: 18px;">New Message has been submitted from your website contact form</p><br>';
$body =
"<br> Below Are the details for the query <br> <b>Name: </b> " .
"<br> <b>Full Name: </b>\n $fname" .
"<br> <b>Phone: </b>: $fnumber" .
"<br> <b>Email: </b> $femail" .
"<br> <b>Subject: </b> $fsubject" .
"<br> <b>Customer Message: </b> $fmessage";
$email_to = "m.ahmed4821#l.com";
$email_from = "no-reply#mrmakt.com"; // Enter Sender Email
$sender_name = "M.A.K.T- Website"; // Enter Sender Name
require "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mrmakt.com"; // Enter Your Host/Server
$mail->SMTPAuth = true;
$mail->Username = "no-reply#mrmakt.com"; // Enter Sender Email
$mail->Password = "";
//If SMTP requires TLS encryption then remove comment from it
//$mail->SMTPSecure = "tls";
$mail->Port = 26;
$mail->IsHTML(true);
$mail->From = $email_from;
$mail->FromName = $sender_name;
$mail->Sender = $email_from; // indicates ReturnPath header
$mail->AddReplyTo($email_from, "No Reply"); // indicates ReplyTo headers
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($email_to);
if (!$mail->Send()) {
$status = "Mailer Error: " . $mail->ErrorInfo;
} else {
?>
<script>
location.replace("index.php?message=your-message-has-been-sent")
</script>
<?php
}
} else {
$msg = "Something Went Wrong. Please try again";
}
?>
after sending the form to new URL I am getting the value using this below ode and trying to display the toast also using the below code
<?php
if (isset($_GET["message"])) {
$querysubmitted = "Thank You....! Your Message has been sent|.";
}
?>
<?php if ($querysubmitted) { ?>
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="imgs/MAKT_FALCON_PMG.png" class="rounded me-2" alt="MAKT_LOGO">
<strong class="me-auto">M.A.K.T</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
<?php echo htmlentities($querysubmitted); ?>
</div>
</div>
<?php } ?>
Please help me with that
thanks in advance

PHP addAttachment($file) causing that email is not sent

This is my site --> nodeiterator.pl
Why when I send email WITHOUT $mail->addAttachment($file); I DO receive email but... when I add $mail->addAttachment($file); I DO NOT receive email on my mailbox even though I receive sussess message...What Am I missing here? My aim is to send form result to my mail box WITH attachement file...
Below This is my PHP script responsible for sending message:
<?php
$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
include_once "phpmailer/PHPMailer.php";
include_once "phpmailer/Exception.php";
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$nazwisko = $_POST['nazwisko'];
$imie = $_POST['imie'];
if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != "") {
$file = "attachment/" . basename($_FILES['attachment']['name']);
move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
} else
$file = "";
$mail = new PHPMailer();
$message = "
<html>
<head>
<meta charset=\"utf-8\">
</head>
<style type='text/css'>
body {font-family:sans-serif; color:#222; padding:20px;}
div {margin-bottom:10px;}
.msg-title {margin-top:30px;}
table {
border-collapse:collapse;
}
</style>
<body>
<table border=\"2\">
<tr>
<td>Nazwisko osoby ubezpiecząjacej :</td>
<td>$nazwisko</td>
</tr>
</table>
</body>
</html>";
$mail->addAddress('piterdeja#gmail.com');
$mail->setFrom($email);
$mail->isHTML(true);
$mail->Body = $message;
$mail->addAttachment($file);
$mail->AllowEmpty = true;
if ($mail->send())
$msg = "Your email has been sent, thank you!";
else
$msg = "Please try again!";
unlink($file);
}
?>

PHP - Form field validation

I have a form that takes in data i am using php to send it to my email once a user has filled in all the required fields. If a field is empty I get a message eg. "Email is required" but the email still sends. I dont know what the problem is any ideas? Idont want to send a email if any field is empty i also dont want refresh the page everytime submit is clicked, I would like to instead just show the "Required message".
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$nameErr = $lastNameErr = $emailErr = $ironingErr = $descriptionErr = $RoomErr = "";
$first_name = $last_name = $email = $ironing = $description = $Rooms ="";
if(isset($_POST['submit'])){
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ironing = $_POST['ironing'];
$Rooms = $_POST['Rooms'];
$Description = $_POST['description'];
if (empty($_POST["first_name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["first_name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["description"])) {
$descriptionErr = "Description is required";
} else {
$description = test_input($_POST["description"]);
}
if (empty($_POST["Rooms"])) {
$RoomErr = "Room number is Required";
} else {
$Rooms = test_input($_POST["Rooms"]);
}
if (empty($_POST["ironing"])) {
$ironingErr = "Ironing is Required";
} else {
$ironing = test_input($_POST["ironing"]);
}
$to = "someemail#gmail.com"; // this is your Email address
$subject = "Order Sumbittion";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: ". "\n\n" . $_POST['Rooms'] ."Ironing: " . $_POST['ironing'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: " . "Number of Rooms: " . $_POST['Rooms'] ."Ironing: ". $_POST['ironing'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
// sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header("Location: index.php");
}
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<p><span class="error">* required field.</span></p>
<div class="col-md-9">
<form action="" method="post">
First Name: <input type="text" name="first_name">
<span class="error">* <?php echo $nameErr;?></span><br>
<br>
Last Name: <input type="text" name="last_name">
<span class="error">* <?php echo $lastNameErr;?></span><br>
Email:
<br>
<input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br>
Ironing?<br>
<input type="radio" name="ironing" <?php if (isset($ironing) && $ironing=="Yes") echo "checked";?> value="Yes">Yes
<input type="radio" name="ironing" <?php if (isset($ironing) && $ironing=="No") echo "checked";?> value="No">No
<span class="error">* <?php echo $ironingErr;?></span>
<br>
Number Of Rooms:
<br>
<input type="text" name="Rooms">
<span class="error">* <?php echo $RoomErr;?></span>
<br>
Description of the House:
<br>
<textarea name="description" rows="10" cols="70"></textarea>
<span class="error">* <?php echo $descriptionErr;?></span>
<br>
<input type="submit" name="submit" value="Submit">
</form>
Quite simply after checking for errors and loading error message variables, you send the email without checking if any errors have been spotted.
So try adding some code before the email is sent to check for any found errors like this for example
First change this line to set the error variables to NULL
$nameErr = $lastNameErr = $emailErr = $ironingErr = $descriptionErr = $RoomErr = NULL;
And then wrap the email sending in a test like this
if (isset( $nameErr) || isset($lastNameErr) || isset($emailErr) ||
isset($ironingErr) || isset($descriptionErr) || isset($RoomErr) ) {
// You have an error
} else {
$to = "someemail#gmail.com"; // this is your Email address
$subject = "Order Sumbittion";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: ". "\n\n" . $_POST['Rooms'] ."Ironing: " . $_POST['ironing'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: " . "Number of Rooms: " . $_POST['Rooms'] ."Ironing: ". $_POST['ironing'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
// sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header("Location: index.php");
}
This code works on my own website, the block of code used to email yourself and the user did not actually have an validation to check if any errors came up in your checks.
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$nameErr = $lastNameErr = $emailErr = $ironingErr = $descriptionErr = $RoomErr = "";
$first_name = $last_name = $email = $ironing = $description = $Rooms ="";
$error = false;
if(isset($_POST['submit']))
{
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ironing = $_POST['ironing'];
$Rooms = $_POST['Rooms'];
$Description = $_POST['description'];
if (empty($_POST["first_name"])) {
$nameErr = "Name is required";
$error = true;
} else {
$name = test_input($_POST["first_name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
$error = true;
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
$error = true;
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
$error = true;
}
}
if (empty($_POST["description"])) {
$descriptionErr = "Description is required";
$error = true;
} else {
$description = test_input($_POST["description"]);
}
if (empty($_POST["Rooms"])) {
$RoomErr = "Room number is Required";
$error = true;
} else {
$Rooms = test_input($_POST["Rooms"]);
}
if (empty($_POST["ironing"])) {
$ironingErr = "Ironing is Required";
$error = true;
} else {
$ironing = test_input($_POST["ironing"]);
}
if ($error === false)
{
$to = "youremail#gmail.com"; // this is your Email address
$subject = "Order Sumbittion";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: ". "\n\n" . $_POST['Rooms'] ."Ironing: " . $_POST['ironing'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: " . "Number of Rooms: " . $_POST['Rooms'] ."Ironing: ". $_POST['ironing'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
// sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header("Location: index.php");
}
}
// You can also use header('Location: thank_you.php'); to redirect to another page.
?>
<p><span class="error">* required field.</span></p>
<div class="col-md-9">
<form action="" method="post">
First Name: <input type="text" name="first_name">
<span class="error">* <?php echo $nameErr;?></span><br>
<br>
Last Name: <input type="text" name="last_name">
<span class="error">* <?php echo $lastNameErr;?></span><br>
Email:
<br>
<input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br>
Ironing?<br>
<input type="radio" name="ironing" <?php if (isset($ironing) && $ironing=="Yes") echo "checked";?> value="Yes">Yes
<input type="radio" name="ironing" <?php if (isset($ironing) && $ironing=="No") echo "checked";?> value="No">No
<span class="error">* <?php echo $ironingErr;?></span>
<br>
Number Of Rooms:
<br>
<input type="text" name="Rooms">
<span class="error">* <?php echo $RoomErr;?></span>
<br>
Description of the House:
<br>
<textarea name="description" rows="10" cols="70"></textarea>
<span class="error">* <?php echo $descriptionErr;?></span>
<br>
<input type="submit" name="submit" value="Submit">
</form>
If you don't want to refresh page, then you can use ajax call to send data on server to validate. Otherwise form will submit and page will refresh every time you slick submit.
And email is being sent every time weather data is valid or not, because there is no condition to check if data is valid. So use a variable and assign it 'false' and before sending check if its still true then send email.
}
First things first , the solution to your issue is that even you caught the error
if (empty($_POST["email"])) {
$emailErr = "Email is required";
}
you did not applied any check to make sure that script execution does not continue , for this you can add die(); also you can take a status variable as $status = 0; if you find any error just assign $status = 1 and before sending email check if($status == 0).
Now if you want to show error message without refreshing the page I would suggest to use jquery or any plugin such as https://validatejs.org/

php coding error not returning to main page

Im new to Php so please be gentle.
I have written a website and i have added a subscribe to newsletter section. The user adds their name and email address before pressing submit. I get the email so the most part is working but the form doesnt return me to the main page of the website. Can anyone point out where i am going wrong please?
Thanks in advance
The code on the website is:
<form name="frmcontact" id="frmcontact" action="php/contact.php" method="post">
<input id="name" name="name" type="text" value="Name"
onblur="this.value=(this.value=='') ? 'Name' : this.value;" onfocus="this.value=(this.value=='Name') ? '' : this.value;" />
<input id="email" name="email" type="text" value="Email"
onblur="this.value=(this.value=='') ? 'Email' : this.value;" onfocus="this.value=(this.value=='Email') ? '' : this.value;" />
<input name="submit" id="send" type="submit" value="Message" />
</form>
The code in contact.php is:
<?php session_start();
if(!$_POST) exit;
$address = 'email#emailaddress.com';
$email_subject ="Add me to the mailing list";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "Please add me to the mailing list ";
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name with regards to $subject.\r\n\n";
$msg .= "$message\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(#mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; }
else
{echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; }
header('Location:http://www.websiteaddress/homepage.html');
?>
Remove All output before header use exit after header and also consider to give space marked below
v
header('Location: http://www.websiteaddress/homepage.html');
exit;
use correct directory path
if(isset($_POST['submit'])){
$address = 'email#emailaddress.com';
$email_subject ="Add me to the mailing list";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "Please add me to the mailing list ";
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name with regards to $subject.\r\n\n";
$msg .= "$message\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(#mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; }
else
{echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; }
header('Location: homepage.html');
}
you cant output anything before using the header()
HTTP-Headers should be sent before any output from the server. If you have an output before, the server will output a warning like 'Headers already been sent'
<?php
ob_start();
echo "redirecting now ....";
header('Location: http://www.websiteaddress/homepage.html');
exit();
ob_end_flush();
?>

Contact form validation and email send. Works. How to do things better?

This code works and works well although I know there are definitely some redundancies and better ways to do things. For one, instead of using form action=mypage.php, I have all the php with all my html code. When I tried to have it all in mypage.php, none of the variables would be found in $_POST. Though isset would result to true on $_POST. So... weird, and screw it, I put it in with the html. I was trying with WAMP, but wouldn't work on the server either.
Another issue, refresh of the page after submission will send another email as well, which might be resolved if I solve the form action issue above.
How's my validation? Anything recommended to improve the process or security?
<h1><div class="titleWrapper"><div class="titleContact">Contact</div></div></h1>
<div class="contact">
<ul class="contactColumn">
<li>
<div class="fields">
<form method='POST'>
<input type="text" name="name" placeholder="Your Name" maxlength="50">
<input type="text" name="email" placeholder="Your Email" maxlength="80">
<textarea name ="message" placeholder="Your Message" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Your Message'" maxlength="2000"></textarea>
<input type="checkbox" name="copy" style="display: inline-block;float:left"><span style="float:left;padding:17px 0 0 5px">Send me a copy</span>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</li>
</ul>
<ul class="contactColumn">
<div class="rightSide">
<p>
Still have questions?
</p>
<p>
Need more information?
</p>
<p>
Feel free to contact us!
</p>
</div>
</ul>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed in your name";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["message"])) {
$comment = "";
} else {
$comment = test_input($_POST["message"]);
}
if (empty($nameErr) && empty($emailErr)){
$to = "myemail#email.com";
$subject = "Contact form submission";
$subject2 = "Copy of your contact form";
$message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $email;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
if (isset($_POST['copy'])) {
mail($email,$subject2,$message2,$headers2); // sends a copy of the message to the sender
}
echo "<div class='errorMessageWrapper'><div class='errorMessage'><div style='color:#333'>
Thank you for contacting us " .
$name .
". We will be in touch shortly. </div></div>";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
if (!empty($nameErr)) {
echo "<div class='errorMessageWrapper'><div class='errorMessage'><li style='list-style-type: circle;'>" . $nameErr . "</li></div></div>";
}
if (!empty($emailErr)) {
echo "<div class='errorMessageWrapper'><div class='errorMessage'><li style='list-style-type: circle;'>" . $emailErr . "</li></div></div>";
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
</div>
I was thinking to make the send email simpler with less code i would suggest PHPMailer it is less code and easier to use.
Take a look at the documentation for PHPMailer at: PHPMAILER DOCUMENTATION
PHPMailer should make it easier to read if you understand PHPMailer, and very simple to write.
HERE IS A EXAMPLE:
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
$mail->From = "from#yourdomain.com";
$mail->FromName = "Full Name";
$mail->addAddress("recipient1#example.com", "Recipient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
Here is a link for the the sending emails with PHPMailer: Link

Categories