I've been trying this for a long but failed till now.
I've tried changing form names, or attributes names but didn't work.
Here is the code for my form:
<form action="contact_process.php" class="office_contact_form" id="contactForm" method="post" name="contactForm" novalidate="">
<div class="form-group col-md-12">
<input class="form-control" id="name" name="name" placeholder="Name" type="text">
</div>
<div class="form-group col-md-12">
<input class="form-control" id="email" name="email" placeholder="Email Address *" type="text">
</div>
<div class="form-group col-md-12">
<input class="form-control" id="subject" name="subject" placeholder="Subject" type="text">
</div>
<div class="form-group col-md-12">
<textarea class="form-control" id="message" name="message" placeholder="Your Message" rows="1"></textarea>
</div>
<div class="form-group col-md-12">
<button class="btn p_btn" type="submit" value="submit">Send Message</button>
</div>
</form>
Here is my PHP code:
<?php
$to = "hello1224#gmail.com";
$from = $_REQUEST['yourname'];
$name = $_REQUEST['youremail'];
$headers = "From: $from";
$subject = "You have a message from your attornyeproducts.com";
$fields = array();
$fields{"yourname"} = "name";
$fields{"youremail"} = "email";
$fields{"subject"} = "subject";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $subject, $body, $headers);
?>
I'm trying to receive the data from the this contact form to the email's id.
Did you tried https://github.com/PHPMailer/PHPMailer ?
simple example: https://github.com/PHPMailer/PHPMailer
example to fit your case:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // 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("YOUREMAIL#gmail.com");
$mail->addAddress("hello1224#gmail.com"); // Add a recipient
$fields = array(
"yourname" => $_REQUEST['yourname'],
"youremail" => $_REQUEST['youremail'],
"subject" => $subject ,
"phone" => "phone",
"message" => "message",
);
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject
$mail->Body = $body;
$mail->AltBody = $body;
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
I did not test your fields. You can test your field to ensure they have correct values and then pass those values to this function.
I suggest you use FILTER_VALIDATE_EMAIL to ensure you have a valid email.
Also you can check that the post keys that you are expecting actually exist:
$message=(isset($_POST['message']))?$_POST['message']:'default message';
function send($subject,$msg,$email,$from,$replyto=null){
$replyto=(isset($replyto) && filter_var($replyto, FILTER_VALIDATE_EMAIL) )?$replyto:'contact#mydomain.com';
$params="-fcontact#mydomain.com";
$subject = $subject;
$message = "<div style='font-family: Arial, Helvetica, sans-serif;'>";
$message .= $msg;
$message .="</div>";
$headers = "From: =?utf-8?b?".base64_encode($from)."?= <contact#mydomain.com>\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= 'Bcc: info#mydomain.com' . "\r\n";
$headers .= 'Reply-To: '.$replyto . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$to = $email;
if(isset($_SERVER['REMOTE_ADDR']) && in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ))) return true;
return mail($email, $subject, $message, $headers,$params);
}
Related
The contact details are not sending. I will appreciate if anyone has any idea what I am doing wrong. The website is already live and I have used the correct email address in PHP. Not sure 100 if there is any info that will go into head of the HTML contact form.
Thanks
HTML Code:
<div class="row">
<div class="col-12">
<br>
<h2 class="contact-title">Get in Touch</h2>
</div>
<div class="col-lg-8">
<form class="form-contact contact_form" action="contact_process.php" method="post" id="contactForm"
novalidate="novalidate">
<div class="row">
<div class="col-12">
<div class="form-group">
<textarea class="form-control w-100" name="message" id="message" cols="30" rows="9"
onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Message'"
placeholder='Enter Message'></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" name="name" id="name" type="text" onfocus="this.placeholder = ''"
onblur="this.placeholder = 'Enter your name'" placeholder='Enter your name'>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" name="email" id="email" type="email" onfocus="this.placeholder = ''"
onblur="this.placeholder = 'Enter email address'" placeholder='Enter email address'>
</div>
</div>
<div class="col-12">
<div class="form-group">
<input class="form-control" name="subject" id="subject" type="text" onfocus="this.placeholder = ''"
onblur="this.placeholder = 'Enter Subject'" placeholder='Enter Subject'>
</div>
</div>
</div>
<div class="form-group mt-3">
<a href="#" class="btn_3 button-contactForm" >Send Message</a>
</div>
</form>
</div>
PHP Code:
<?php
$to = "i have used a correct email address";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = $_REQUEST['subject'];
$number = $_REQUEST['number'];
$cmessage = $_REQUEST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "You have a message from your Bitmap Photography.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title>
</head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
$send = mail($to, $subject, $body, $headers);
?>
The contact details are not sending. I will appreciate if anyone has any idea what I am doing wrong. The website is already live and I have used the correct email address in PHP. Not sure 100 if there is any info that will go into head of the html contact form.
You have to make a couple of changes in your code to make the mail work. First you Have to change the code for the button. It must be like: <button type="submit"class="btn_3 button-contactForm">Send Message</button> you also have to change the code in the PHP file for sending the mail you have to remove the $send and make it just like mail($to, $subject, $body, $headers); You also have to note that not all hosting companies support the mail() PHP function. So make sure your web hosting provider supports the mail() function. If your hosting service does not support the PHP mail() function, you have to use the PHPMailer class. PHPMailer uses SMTP and sends the mail with the form data. You can download the PHPMailer class with composer. There are also other websites you can download that from. After you unzip the downloaded zip file, you would notice there is a folder named PHPMailer which has a lot of other PHP files inside it. You don't have to change any other PHP files. Make sure an autoload.php file is present in the folder, because the autoload.php file is the file which gets and combines all the necessary classes for the SMTP mail. After that, you have to upload the PHPMailer folder to your root directory in your server (with FTP for shared hosting or just copy paste for dedicated servers). First You have to create a gmail or any mail account through which the PHPMailer sends the mail. After creating an account, go to settings of the account and make sure 2 step authentication is disabled. After that also turn on Less Secure app, which you can do from here.
After doing all that, you have to create two PHP files which sends the form data, the first one will be contact_process.php as you mentioned above and the code for the php file will be:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmail/vendor/autoload.php';
if($_POST)
{
require('constant.php');
$user_name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$msg = filter_var($_POST["msg"], FILTER_SANITIZE_STRING);
$mail = new PHPMailer(true);
// $mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail -> Host = HOST; //this gets called from the constant.php
$mail->Username = USERNAME;
$mail->Password = PASSWORD;
$mail->From = $user_email;
$mail->FromName = $user_name;
$mail->addAddress(RECIPIENT_MAIL,RECIPIENT_MAIL_NAME); //this gets called from the constant.php do not change this
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = "New Response from website :\n\n<br>".
"Name: $user_name\n\n<br>".
"Email: $user_email \n\n<br>".
"Subject: $subject \n\n<br>".
"Message: \n\n <br>". "$msg\n\n<br>";
$mail->AltBody = "This is the plain text version of the email content";
if (!$mail->send()) {
echo json_encode(array('type'=>'error', 'text' => 'Try Again later')); //error sending form
exit;
} else {
//mail sent successfully
header("Location: thankyou.php");//change the link to the thank you page
exit;
}
}
?>
Now a constant.php file must be created where the reciepient and sender must be configured. The code for that will be:
<?php
// SMTP Configuration
define('HOST',"ssl://smtp.gmail.com");
define('USERNAME',"sending-mail#gmail.com"); //mail address of gmail you created
define('PASSWORD',"password-of-sending-mail-acc"); //password of gmail you created
// Recipient Configuration
define('RECIPIENT_MAIL',"recipient#gmail.com"); //enter mail address you want the form data to get received
define('RECIPIENT_MAIL_NAME',"Website"); //name of recipient
?>
Make sure all the files are in the root directory. You can also add the files to other directories but have to change the directory linking for the files.
For more Detailed documentation and source code you can see this.
This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 6 years ago.
I'm a little bit new with with php and i just want to ask how can i make the the "Send Message" button send the inputted information on the form i created to my email.
Here's the code:
<section id="three">
<h2>Email Me!</h2>
<p>You will receive a reply within 24-48 hours.</p>
<div class="row">
<div class="8u 12u$(small)">
<form method="post" action="MAILTO:sample#email.com">
<div class="row uniform 50%">
<div class="6u 12u$(xsmall)"><input type="text" name="name" id="name" placeholder="Name" /></div>
<div class="6u$ 12u$(xsmall)"><input type="email" name="email" id="email" placeholder="Email" /></div>
<div class="12u$"><textarea name="message" id="message" placeholder="Message" rows="4"></textarea></div>
</div>
</form>
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
<div class="4u$ 12u$(small)">
<ul class="labeled-icons">
<li>
<h3 class="icon fa-home"><span class="label">Address</span></h3>
1234 Somewhere Rd.<br />
Nashville, TN 00000<br />
United States
</li>
<li>
<h3 class="icon fa-mobile"><span class="label">Phone</span></h3>
000-000-0000
</li>
<li>
<h3 class="icon fa-envelope-o"><span class="label">Email</span></h3>
hello#untitled.tld
</li>
</ul>
</div>
</div>
</section>
Thanks!
I'm not quite sure but email from php server almost all of them ends up in spam folder (trust issues by mail provider). But if you're interested, you can send mail via email function:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
source: PHPDocs
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
What I recomend using is Mail sending servive like SendGdrid or MailChimp, those are easy to use and have pretty simpe API to work with. Free plan has a lot to offer, And you can send plain html through their api and it will be fine.
<?php
if(isset($_POST['submit'])) // on submit click no need to action of the form
{
$name = $_POST['name'];
$email = $_POST['email'];
$to = "somebody#example.com";
$subject = "My subject";
$body = "name:" . $name . "Email:" . $email;
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$body,$headers);
}
?>
I would recommend using PHPMailer to send email from PHP. Here's the steps to accomplish this.
Go to the Github repository.
Download the ZIP.
Extract it in your public_html directory.
include '/path/to/PHPMailer/PHPMailerAutoload.php'; at the top of your PHP script.
Get the values from the HTML form like you normally would.
Here's an example...
index.html
<form action="index.php" method="post">
<input type="email" name="email">
<input type="text" name="name">
<input type="text" name="subject">
<input type="text" name="message">
</form>
index.php
include '/path/to/PHPMailer/PHPMailerAutoload.php';
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, "ssl" also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('your email', 'your name'); // from
$mail->addAddress($email, $name); // to
$mail->isHTML(true); // if html
$mail->Subject = $subject;
$mail->Body = $message; //HTML
if($mail->send()){
echo 'Mail sent!';
}
else {
echo 'Mail failed!';
}
I have php website when try to submit contact form Post method not working. All of form elements inside of index.html i'll share the codes with you. I'll be happy if you could help me
In HTML File (index.php)
<form id="main-contact-form" method="post" action="sendemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="İsim Soyisim" required>
</div>
<div class="form-group">
<input type="email" name="mail_adress" class="form-control" placeholder="Mail Adresi" required>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Konu" required>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="8" placeholder="Mesaj" required></textarea>
</div>
<button type="submit" name="send" class="btn btn-primary">Mesaj Gönder</button>
</form>
in PHP (sendemail.php)
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xx#xxxxx.com'; // SMTP username
$mail->Password = 'xxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('xxx#xxxxxx.com', 'xx xx xx'); //Set who the message is to be sent from
$mail->addAddress('xxx#xxxxx.com', 'xx xx xx xx'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = 'Mesaj Konusu'.$_POST['name'];
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
echo $_POST['subject'];
exit;
}
echo 'Message has been sent';
?>
Thank You
Try to compare with the === operador, to compare not only the same value, but also the same data type.
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// …
}
I found the answer ajax prevent to POST method when i fix that everthings are became good
var form = $('#main-contact1-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Mail Gönderiliyor...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">Mesajınız başarı ile iletilmiştir. En kısa sürede tarafınıza dönüş yapılacaktır.</p>').delay(3000).fadeOut();
});
});
when i delete this code everythings are good. How to fix that without delete it..? That's a new question to ask...
<?php
function sendmail($to,$subject,$message,$from)
{
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = "From: " . $from. "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
}
?>
you write ==POST(capital letters), and use method = post(small letters), so change it to small or capital in both places. or check sendmail.php
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
This is my php code to send email. I got the massage 'Message was sent, you can send another one' But email is not sending.
<h4>Please fill out the following form and we will be in touch with you soon.</h4>
<form action="mytest.php" method="post" id="contactform">
<ol>
<li>
<label for="name">Your Name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="message">Message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
<div class="clr"></div>
</li>
</ol>
</form>
<?php
if(!$_POST) exit;
$email = $_POST['email'];
$errors=0;
if($errors==1) echo $error;
else{
$email_from = $_POST['email'];
$email_from = "from#gmail.com";
$headers = "From: " . strip_tags( $_POST['name'] ) . "\r\n";
$mail_to_send_to = "to#gmail.com";
$your_feedbackmail = "from#gmail.com";
$sendflag = 'send';
if ( $sendflag == "send" )
{
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $your_feedbackmail" . "\r\n" . "Reply-To: $email" . "\r\n" ;
$a = mail( $mail_to_send_to, "Feedback Form Results", $message, $headers );
if ($a)
{
print("Message was sent, you can send another one");
} else {
print("Message wasn't sent, please check that you have changed emails in the bottom");
}
}
}
?>
I'm Using Cpanel to host my web site. Is there any special configurations to do this? I'm new to php. Please help me.
mail function doesn't provide authentication functionality. Your have to use Mail class from Mail Pear package. See here for an example:
example
I am assuming you are on shared hosting based on the fact that you are using Cpanel, some shared hosting solutions don't play nicely with php's mail() function, I have found that using phpmailer https://github.com/PHPMailer/PHPMailer works better and provides more functionality
to use phpmailer :
download from the link, place the files in your a folder accessible to your web application.
code :
$email_from = $_POST['email'];
$email_from = "from#gmail.com"; // this overwrites the $_POST['email'] value, check this
$email_from_name = "Nishanthi";
$gmailUsername = "from#gmail.com";
$gmailPassword = "mysecretpassword";
$mail_to_send_to = "to#gmail.com";
$your_feedbackmail = "from#gmail.com";
$emailSubject = "Place Subject Here";
$emailContent = "This message can contain <b>HTML</b>";
require '[path_to_your_phpmailer_files]/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2; //Enable SMTP debugging
$mail->Debugoutput = 'html'; //Ask for HTML-friendly debug output
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $gmailUsername; // SMTP username
$mail->Password = $gmailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($email_from, $email_from_name);
$mail->addAddress($mail_to_send_to);
$mail->addReplyTo($your_feedbackmail);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $emailSubject;
$mail->Body = $emailContent;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message was sent, you can send another one';
}
?>
I've tried out a few PHP contact form tutorials but none seem to work for me. I'm not sure what I'm doing wrong. I tested it in localhost and nothing, so I went ahead and hosted it to see if that would work but still nothing.
HTML
<form class="form" action="form_process.php" method="post" name="contact_form">
<p class="name">
<label for="name">Name</label><br>
<input type="text" name="name_first" id="name" placeholder="First" />
<input type="text" name="name_second" id="name" placeholder="Last" />
</p>
<p class="email">
<label for="email">Email</label><br>
<input type="text" name="email" id="email" placeholder="mail#example.com" />
</p>
<p class="text">
<label for="email">Comments</label><br>
<textarea name="text" placeholder="Write something to us" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
form_process.php
<?php
$name_first = $_POST['name_first'];
$name_second = $_POST['name_second'];
$email = $_POST['email'];
$text = $_POST['text'];
$from = 'From: ';
$to = 'EMAIL HERE';
$subject = 'Hello';
$body = "From: $name_first\n $name_second\n E-Mail: $email\n Message:\n $text";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
header("Location: index.html");
echo '<p>Your message has been sent!</p>';
exit;
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
Your error is from the line
if ($_POST['submit']) {
This is because you did not give your submit button a name of submit. If you fix this line in your HTML it should fix the issue:
<input type="submit" name="submit" value="Send" />
I recommend that you set an error log in your php.ini file. That way you can see the error for yourself which would have said something similar to:
PHP Notice: Undefined index: submit in
/var/www/pwd/blah/form_process.php on line 12
If you are working in localhost mode you will need phpmailer.
First you need download phpmailer from here https://github.com/PHPMailer/PHPMailer/archive/master.zip
Then paste in your folder. If my coding doesn't clear you, you can check from
https://github.com/PHPMailer/PHPMailer
<?php
require 'PHPMailerAutoload.php'; // Your Path
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // Your mail
$mail->Password = 'secret'; // Your mail password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // 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');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
//Check Condition
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Second way.
If you working testing in online mode(Have own domain and hosting), you can just randomly copy and paste.
Doesnt required phpmailer.
if(isset($_POST['email'])) $email = $_POST['email'];
else $email = "";
function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$myname."\" <".$myemail.">\r\n";
return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers));
}
if(isset($Submit) && $Submit=="Go") {
$emailContent ='';
$sent=send_mail($name, "yourmailname.gmail.com", "Fido", $receipientEmail, "Testing", $emailContent);
if($sent) {
echo $emailContent;
header('Location: contact.php');
}else{
echo "Failed";
exit;
}
}
?>
Regards