<div class="contact_form clearfix" id="Contact">
<h2>Hello... You can send me message to my universe here.</h2>
<img src="img/planeta1.png" alt="">
<form class="clearfix spaceForm" action="contactform.php" metod="post" >
<label for="name">Your name:</label>
<input type="text" name="name" id="name" placeholder="Jon Doe" required>
<label for="email">Your email:</label>
<input type="text" name="email" id="email" placeholder="something#mama.com" required>
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject" required>
<label for="message">Your message:</label>
<textarea name="message" id="message" required></textarea>
<button type="submit" name="submit">Send mail</button>
</div>
and php code here...
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "pisitenam#sammostalnisindikatstark.org.rs";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from " .$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html");
}
?>
My contact form instead to send message download on computer as php file. I uploaded my site to netfly but stil doesnt work.
Can anybody help and give me a hint where is problem?
On XAMPP im getting blank page and mail is not sent. When I uploaded site on netfly site works fine but contact from when click submit start download php file where is code writen for controling contact form.5 day im trying to find solution for this problem and im geting tired :D So if anybody can help...
you are having some spell mistake in your form tag, first of all correct the method spell in your code as it is not correct so it can't redirect and post your data to contact form.
mail library contains various function.
for example:
<?php require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'your_smtp_domain.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
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('john#example.net', 'John doe'); // Add a recipient
$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>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
this can works for you if you use library.
Related
I can't seem to find the solution for this or an answer online.
It is using Bootstrap and PHPmailer.
Below is my HTML for the form:
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="row">
<form name="coming-soon-form" role="form" autocomplete="off" class="m-t-15" id="coming-soon-form" action="_lib/coming-soon-form.php" method="post">
<div class="row">
<div class="col-sm-6">
<div class="form-group form-group-default required">
<label class="control-label">First name</label>
<input type="text" id="name" name="name" class="form-control" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group form-group-default">
<label class="control-label">Last name</label>
<input type="text" id="last-name" name="last-name" class="form-control" required>
</div>
</div>
</div>
<div class="form-group form-group-default">
<label class="control-label">Email</label>
<input type="email" id="email" name="email" placeholder="abc#123.com" class="form-control" required>
</div>
<div class="sm-p-t-10 clearfix">
<input type="submit" class="btn btn-complete font-montserrat all-caps fs-12 pull-right xs-pull-left" value="Submit">
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
and here is the php script in the "coming-soon-form.php" file:
<?php
require 'phpmailer/PHPMailerAutoload.php';
// CONFIG YOUR FIELDS
//============================================================
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
// CONFIG YOUR EMAIL MESSAGE
//============================================================
$message = '<p>The following request was sent from: </p>';
$message .= '<p>Name: ' . $name . '</p>';
$message .= '<p>Email: ' . $email . '</p>';
$message .= '<p>Message: ' . $formMessage .'</p>';
// CONFIG YOUR MAIL SERVER
//============================================================
$mail = new PHPMailer;
$mail->isSMTP(); // Enable SMTP authentication
$mail->SMTPAuth = true; // Set mailer to use SMTP
//Sign up with MAIL GUN
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server (this is a fake name for the use of this example)
$mail->Username = 'email#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
$mail->From = $email;
$mail->FromName = $name;
$mail->AddReplyTo($email,$name);
$mail->to('email#gmail.com');
$mail->addAddress('email#gmail.com'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Contact request';
$mail->Body = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
$data['error']['title'] = 'Message could not be sent.';
$data['error']['details'] = 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
$data['success']['title'] = 'Message has been sent';
echo json_encode($data);
?>
I also have validation through jquery-validation which works fine.
However, once the form is filled out and submitted, it doesn't properly execute, send an email, or display any error or success message on the page as it should. Instead, it simply loads a blank page and the URL is www.domainnamehere.com/_lib/coming-soon-form.php
I also validated all the php using a validator.
What is causing the form submit issue???
Below is the error log information:
[23-Aug-2017 03:25:02 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0 [23-Aug-2017 03:25:02 UTC] PHP Fatal error: Uncaught Error: Call to undefined method PHPMailer::to() in /home4/anabasi2/public_html/_lib/coming-soon-form.php:34 Stack trace: #0 {main} thrown in /home4/anabasi2/public_html/_lib/coming-soon-form.php on line 34
The following line is not a valid PHPMailer method:
$mail->to('email#gmail.com');
The line below is the correct way to add a recipient.
$mail->addAddress('email#gmail.com');
This is the correct way to send email with the PHPMailer :
$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';
$mail->SMTPAuth = true;
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('from#example.com', '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);
$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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
please consider about your usage of $mail->From and $mail->To method .
I created a simple form on my page and now I tried to add php script to sending email. Unfortunately it does not work. After clicking on the button, I want the user to remain on my side without redirection.
mail_sender.php
<?php
if(isset($_POST['submit'])){
$to = "someone#gmail.com";
$from = $_POST['email'];
$message = " You received the fallowing message:" . "\n\n" . $_POST['message'];
mail($to,$message,$from);
echo "Mail Sent. Thank you, we will contact you shortly.";
}
?>
HTML
<form action="mail_sender.php" method="post">
<textarea id="email" name="email" rows="1" cols="30" placeholder="Type your email"></textarea>
<textarea id="formContent" name="message" rows="6" cols="30" placeholder="Type your message"></textarea>
<input type="submit" id="submit" value="Send">
</form>
First of all name attribute is missing in your submit button. And php mail function is wrong.
It should be:
$subject = "Your subject";
$headers = "From: $from ";
mail($to,$subject,$message,$headers);
instead of:
mail($to,$message,$from);
PHP's default mail() function doesn't work most of the times, especially with GMail. This is because your e-mail needs to be formatted in a special way to be accpeted by Google's mail server. You'll be better off using a mail library like PHPMailer.
Here's how to send an e-mail using PHPMailer from a GMail Account.
$mail = new PHPMailer();
// ---------- adjust these lines ---------------------------------------
$mail->Username = "xxx#gmail.com"; // your GMail user name
$mail->Password = "passwd"; // your GMail Password
$mail->AddAddress("yyy#gmail.com"); // recipients email
$mail->FromName = "Your Name"; // readable name
$mail->Subject = "Subject";
$mail->Body = "Body";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
//----------------------------------------------------------------------
if(!$mail->Send())
{
echo "mail sent";
}
I tried everything and now i received message SMTP ERROR: Failed to connect to server and SMTP connect() failed
<form action="mail_sender.php" method="post">
<textarea id="email" name="email" rows="1" cols="30" placeholder="Type your email"></textarea>
<textarea id="formContent" name="message" rows="6" cols="30" placeholder="Type your message"></textarea>
<input type="submit" name="submit" id="submit" value="Send">
</form>
PHP
<?php
require "PHPMailer-master/PHPMailerAutoload.php";
$mail = new PHPMailer();
$to = "someone#gmail.com"; // required
$from = $_POST['email'];
$comment =
'Email: '.$from.' <br> />
Message: '.$_POST['message'].' <br> />'
;
$mail->Username = "someone#gmail.com"; // your GMail user name
$mail->Password = "Password"; // your GMail Password
$mail->AddAddress("someone#gmail.com"); // recipients email
$mail->setFrom($_POST['email']);
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Subject = 'Here is the subject';
//----------------------------------------------------------------------
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
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 have this form:
<form action="/sendemail.php" id="main-contact-form" method="post" name="contact-form" role="form">
<div class="form-group">
<input class="form-control" id="name" name="name" placeholder="put your name" required="" type="text" />
</div>
<div class="form-group">
<input class="form-control" id="email" name="email" placeholder="Email" required="" type="email" />
</div>
<div class="form-group">
<input class="form-control" id="subject" name="subject" placeholder="Subject..." required="" type="text" />
</div>
<div class="form-group">
<textarea class="form-control" name="message" placeholder="Mensaje" required="" rows="8"></textarea>
</div>
<input class="btn btn-primary" id="submit" name="submit" type="submit" value="Enviar" />
and this is sendemail.php:
<?php
$pos = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email'];
$to = 'email#gmail.com ';
$subject = 'contact message ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message\n $pos";
mail ($to, $subject, $body, $from)
?>
the email is arrive empty, i try a lot of stuffs but always comes in the same way, is like the form canĀ“t pass the data from inputs to php variables. im new in php so, any help is welcome.
thanks.
The use of mail() function is so insecure and is a vector attack to send massive spam, don't use anymore, for this reason is better to use PHP Mailer libray.
Create a EMAIL account (example: no-reply#domain.com) in your hosting and after that install this library PHP Mailer, now you can do this:
<?php
require 'PHPMailerAutoload.php';
$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'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#example.com', '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';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
UPDATE
After some research I've found that:
You need to ask godaddy technical support to enable "sendmail".
PHP mail() not working on GoDaddy
----------
I've tested your code and it works. I've received the email with ALL the $_POST contents without any problems.
$pos = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email'];
$to = 'email#gmail.com ';
$subject = 'contact message ';
NOTE:
1 - $pos = $_POST; is an array and it will be displayed as Array.
2 - Emails sent via mail() will most likely end-up on the spam folder (read the comments below).
I am trying to set up a contact form at the bottom of my page. I am using PHPMailer and trying to receive emails at my gmail account. Every time I submit the form, my url changes to url/email.php and I get a blank page. What am I doing wrong? Can anyone see the glaring error that I am obviously missing?
HTML:
<div class="container-fluid">
<form action="email.php" id="contact-me" method="post" name="contact-me">
<div class="row-fluid">
<div class="form-group">
<div class="col-md-3 col-md-offset-3">
<input class="input" name="name" id="name" placeholder="Name" type="text">
</div>
<div class="col-md-3">
<input class="input" id="email" name="email"
placeholder="Email" type="text">
</div>
</div>
</div>
<div class="form-group">
<textarea class="input input-textarea" id="message" name="message" placeholder="Type your message here" rows=
"5"></textarea>
</div>
<input name="send" class="send" type="submit" value="Get In Touch">
</form>
</div>
</section>
PHP:
<?php
if (isset($_POST['submit']))
{
require('PHPMailer-master/PHPMailerAutoload.php');
require_once('PHPMailer-master/class.smtp.php');
include_once('PHPMailer-master/class.phpmail.php');
$name = strip_tags($_Post['name']);
$email = strip_tags($_POST['email']);
$msg = strip_tags($_POST['message']);
$subject = "Message from Portfolio";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'me#gmail.com';
$mail->Password = '***********';
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress("me.com", "Katia Sittmann");
$mail->AddReplyTo($email, $name);
$mail->isHTML(true);
$mail->WordWrap = 50;
$mail->Subject =$subject;
$mail->Body = $msg;
$mail->AltBody ="No message entered";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}else{
header("Location: thank-you.html");
}
}
?>
You've got some very confused code here. You should start out with an up-to-date example, not an old one, and make sure you're using the latest PHPMailer (at least 5.2.10).
Don't do this:
require('PHPMailer-master/PHPMailerAutoload.php');
require_once('PHPMailer-master/class.smtp.php');
include_once('PHPMailer-master/class.phpmail.php');
All you need is this, which will auto-load the other classes if and when they are needed:
require 'PHPMailer-master/PHPMailerAutoload.php';
This won't work:
$name = strip_tags($_Post['name']);
PHP variables are case-sensitive, so do this:
$name = strip_tags($_POST['name']);
This will cause problems:
$mail->From = $email;
When you do this, you're forging the From address, and it will get rejected by SPF checks. Put your own address in here, and let the reply-to carry the submitter's address, as you're already doing.
Submit may not be included in the submission if the form is not submitted via that control, e.g. if it's submitted by hitting return in a text input. Check for a field that you know will always be in a submission:
if (array_key_exists('email', $_POST)) {...
Adding a try/catch will not achieve anything - PHPMailer does not throw exceptions unless you ask it to, and you are not.
You are applying strip_tags on the body, but then calling $mail->isHTML(true); - do you want HTML or not?
All that said, none of those things will cause a blank page. It's fairly likely you are running into gmail auth problems which are popular lately, and to see that you need to enable debug output:
$mail->SMTPDebug = 2;
and then read the troubleshooting guide on what you see.