PHP and CKEditor included image does not show in the email - javascript

I have the following page to send newsletters.
page
When I include an image from the toolbar icon. It displays correctly realtime. But however when I click Send, email gets the message without the image. Just only the message (formatted text by the editor shows correctly)
My image is located in this URL: http://raveen.comlu.com/sport.jpg
Also I print content made by the editor after sending message as well;
Even there also, image does not show on the page(see screenshot)
I have the following code;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> A simple page with CKEditor </title>
<script src="ckeditor/ckeditor.js"> </script>
</head>
<body>
<form method="post" action="">
<!-- Create a <textarea> element first -->
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
//replace the <textarea id="editor1"> with a CKEditor instance
CKEDITOR.replace( 'editor1' );
//Retrieve data from CKEditor instance with ID of editor1
var data = CKEDITOR.instances.editor1.getData()
</script>
<input type="submit" name="btnSubmit" value="Send">
</form>
<?php
if( isset($_POST['btnSubmit']) ){
$editor_data = $_POST['editor1'];
echo $editor_data;
$to = "receiver1#yahoo.com, receiver2#gmail.com";
$subject = "Here is the subject";
$message = $editor_data;
$header = "From: Sender Name <senderemail#gmail.com> \r\n";
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type:text/html;charset=UTF-8 \r\n";
$retval = mail( $to, $subject, $message, $header );
if( $retval == true ){
echo "Message sent successfully";
}
else{
echo "Message could not be sent!";
}
}
?>
</body>

All of your quotes from your editor data are being escaped so you can try adding this line before echo $editor_data;
$editor_data = stripslashes($editor_data);

Related

HTML website Javascript alert after php form submission

I have Html website. There is newsletter signup form in the html. It is processed by php script file for sending the email. After the form submission I want it back to the original page and also an alert message for "Thank you for newsletter signup"
HTML :
<div class="col-xs-12 col-sm-12 col-md-6 newsletter-form">
<form name="contactform" method="post" action="scripts/contact.php" onsubmit="return ValidateForm(contactform)">
<input type="text" name="stremail" placeholder="Your email address" ><input type="submit" value="Submit">
</form>
</div>
Javascript Validation :
function ValidateForm(Form)
{
if (Form.stremail.value == "") {
alert("Please enter \"Email\" ");
Form.stremail.focus();
return (false);
}
if ((/^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form.stremail.value)) == false) {
alert("Invalid E-mail Address! Please re-enter.");
Form.stremail.focus();
return (false);
}
return (true);
}
PHP Script :
$stremail = $_POST["stremail"];
$to = "thebrandtgroupre#gmail.com";
$from = $stremail;
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers. = "From: \"$from\" <$from>\r\nReply-To: \"$from\" <$from>\r\nX-Mailer: PHP/".phpversion();
$headers. = "BCC: luxuryproperties#gmail.com,pnparamasivan#gmail.com".
"\r\n"; //for testing purpose
$subject = "The Brandt Group Newsletter Signup";
$message = "Dear Administrator,\r\n\n";
$message = $message.
"The following information was submitted to the website:<br/><br/>";
$message = $message.
"Email Address : ".$stremail.
"<br/><br/>";
mail($to, $subject, $message, $headers);
header("Location: {$_SERVER["
HTTP_REFERER "]}");
$message2 = "Thank you for newsletter signup";
echo "<script type='text/javascript'>alert('Thank you for newsletter signup');</script>";
Any help ?
If you are using Jquery you can do like this:
HTML side
<div class="col-xs-12 col-sm-12 col-md-6 newsletter-form">
<form name="contactform" method="post">
<input type="text" class="stremail" name="stremail" placeholder="Your email address" >
<input type="submit" value="Submit">
</form>
</div>
The form action and onsubmit attributs have been removed
A class has been added on stremail input
Javascript
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(function(){
var form = $('form ');
form.submit(function(e) {
e.preventDefault();
if(ValidateForm(Form)) {
var data = {
'stremail' : $('.stremail').val()
}
$.post("scripts/contact.php", data, function(response) {
if(response.success) {
alert(response.success);
}
else {
// YOUR LOGIC WHEN ERROR OCCURED
}
});
}
});
function ValidateForm(Form) {
if (Form.stremail.value == "") {
alert("Please enter \"Email\" ");
Form.stremail.focus();
return(false);
}
if ((/^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Form.stremail.value)) == false) {
alert("Invalid E-mail Address! Please re-enter.");
Form.stremail.focus();
return (false);
}
return(true);
}
});
</script>
PHP Side
Verify $_POST data and return response by type
<?php
$response = [];
if(isset($_POST["stremail"]) && !empty($_POST["stremail"])) {
$stremail = $_POST["stremail"];
$to="thebrandtgroupre#gmail.com";
$from = $stremail;
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .="From: \"$from\" <$from>\r\nReply-To: \"$from\" <$from>\r\nX-Mailer: PHP/".phpversion();
$headers .="BCC: luxuryproperties#gmail.com,pnparamasivan#gmail.com" . "\r\n";//for testing purpose
$subject = "The Brandt Group Newsletter Signup";
$message = "Dear Administrator,\r\n\n";
$message = $message ."The following information was submitted to the website:<br/><br/>";
$message = $message ."Email Address : ".$stremail."<br/><br/>";
mail($to,$subject,$message,$headers);
$response['success'] = "Thank you for newsletter signup";
}
else {
$response['error'] = "YOUR_ERROR_MESSAGE";
}
return $response;
?>
The alert will not happen because you have already called header to redirect the user. To accomplish your goal of a javascript popup I'd perhaps set a session variable after the email has been sent and then when you are redirected back to the signup page, assuming that it is a PHP enabled page, you can test for that session and perform the javascript alert.
<?php
/* mail handler */
session_start();
$stremail = $_POST["stremail"];
$to="thebrandtgroupre#gmail.com";
$from = $stremail;
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: \"$from\" <$from>\r\nReply-To: \"$from\" <$from>\r\nX-Mailer: PHP/".phpversion();
$headers .= "BCC: luxuryproperties#gmail.com,pnparamasivan#gmail.com\r\n";
$subject = "The Brandt Group Newsletter Signup";
$message = "
Dear Administrator,
The following information was submitted to the website:
<br/><br/>
Email Address: {$stremail}
<br /><br />";
mail( $to, $subject, $message, $headers );
header( "Location: {$_SERVER["HTTP_REFERER"]}");
$_SESSION['mail']=true;
$message = "Thank you for newsletter signup";
?>
The signup page
<?php
session_start();
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>signup</title>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 newsletter-form">
<form name="contactform" method="post" action="scripts/contact.php" onsubmit="return ValidateForm(this)">
<input type="text" name="stremail" placeholder="Your email address" />
<input type="submit" />
</form>
</div>
<?php
if( !empty( $_SESSION['mail'] ) && $_SESSION['mail']==true ){
printf('<script>alert("%s");</script>', $message );
unset( $_SESSION['mail'] );
}
?>
</body>
</html>

Phonegap contact form : How to send contact form message in html using phonegap

Ive a HTML page and converted in phonegap it has a contact.html in contact form i have name mail-id and comments.And i want all the three fields to be mailed into my Mail-id . how to achieve this.
My Php page is in some free webhosting site like http://www.kishorebt.net84.net/contact-form-handler.php so whenever i click send i get the php code in my browser.
My page in not running in server so how to achieve this.
My html page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
</head>
<body>
<h1>Contact us</h1>
<form method="POST" name="contactform" action="http://www.kishorebt.net84.net/contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
<script language="JavaScript">
var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
</body>
</html>
and my php page
<?php
$errors = '';
$myemail = 'kishorebt11#gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
#kishore,
this is a good example CGI to turn into an App. Start by converting your HTML4 to HTML5. You can use my generic boilerplate to get started. There are three (3) big differences to note.
The new opening element for html5 is:
<!DOCTYPE html>
The next most important element is
<meta name="viewport" content="width=device-width">
The third is the listener. Many beginners trip on this part. It is important for this listener to be added. It allows the phonegap library to prepare all the devices on the phone before you call any of the libraries.
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
//
function onDeviceReady() {
If however, you are not going to use the devices, you should at least have a <body onload=loaded()>
I suspect you have more questions. If so, there are two other forums to ask questions in.

Custom Text To Autofill Textarea When DropDown Option Selected

I need some help with the autofill in the textarea when I select the drop down. I tried it and it works perfect on jsfiddle but when I upload the script on my web hosting nothing is happening. I don't know where I am wrong.
<?php
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: SocialDealers <admin#admin.com>' . "\r\n";
$emailList = explode("\n",$_POST['EmailList']);
if(count($emailList) > 0){
foreach($emailList as $to){
$to = trim($to);
$sent = mail($to,$subject,$message,$headers);
if ($sent){
echo "<p>Sent: $to</p>";
}
else{
echo "<p>Not Sent: $to</p>";
}
}
}
else{
echo "<p>No email addresses</p>";
}
?>
<html>
<head>
<script>
var contentToInsert = 'Hi Amey';
$( "#listbox" ).change(function() {
if ($( "#listbox" ).val() == '2') {
$("#EmailBody").html(contentToInsert);
} else {
$("#EmailBody").html("");
}
});
</script>
</head>
<center>
<form method="post">
<br><strong>PHP Email Sender</strong><br><br><br>
Email List<br>
<textarea name="EmailList" placeholder="email#email.com (New Email Each Line)" rows="20" cols="50"></textarea><br><br>
Subject<br>
<input type="text" name="EmailSubject" placeholder="Your Subject Goes Here"><br><br>
Select Automated HTML Content<br>
<select id="listbox">
<option id="option1">Select Offers...</option>
<option id="option2">1</option>
<option id="option3">2</option>
</select>
<br><br>
Body<br>
<textarea name="EmailBody" id="EmailBody" placeholder="Write your content (HTML Accepted)" rows="20" cols="50"></textarea><br><br>
<input type="submit" value="Submit!">
</form><br><br>
</center>
</html>
I don't know where i missed it but i tried all day to figure out the problem and i am not understanding anything. Also if it would be possible i would want the selection text to be from another text file.
Example:
The main file name would be mail.php
Option 1 Select's some text which would be in other file named abctext.txt
If it's working in Jsfiddle and not in your hosted environment , then you need to make sure that you referenced the JQuery library in your code.
Get the html code of your compiled page and check if there is a reference to the Jquery JS file

event.preventDefault(); not working when submitting form

I am trying to put the result from a submitted form in to a div instead of opening it inside a new window. The problem is that my event.preventDefault(); doesn't seem to be working and I don't understand why. The result, after I hit the submit button is always to open the contact-form-handler.php, which is the script file.
Here is the code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
CONTACT FORM:
<form class="form-container" id="contactForm" method="post" action="contact-form-handler.php">
<div class="form-title">Full Name:</div>
<input class="form-field" type="text" name="name" /><br />
<div class="form-title">Email Address:</div>
<input class="form-field" type="text" name="email" /><br />
<div class="form-title">Phone Number:</div>
<input class="form-field" type="text" name="phone" /><br />
<div class="form-title">Message:</div>
<textarea class="form-field" rows="8" cols="34" name="message"></textarea><br />
<div id="contactResponse"></div>
<div class="submit-container">
<button type="submit" class="submit-button">Send</button>
</div>
</form>
SCRIPT CODE:
<script type="text/javascript">
$("#contactForm").submit(function(event)
{
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
$submit = $form.find( 'button[type="submit"]' ),
name_value = $form.find( 'input[name="name"]' ).val(),
email_value = $form.find( 'input[name="email"]' ).val(),
phone_value = $form.find( 'input[name="phone"]' ).val(),
message_value = $form.find( 'textarea[name="message"]' ).val();
/* Send the data using post */
var posting = $.post( "contact-form-handler.php", {
name: name_value,
email: email_value,
phone: phone_value,
message: message_value
});
posting.done(function( data )
{
/* Put the results in a div */
$( "#contactResponse" ).html(data);
/* Change the button text. */
$submit.text('Sent, Thank you');
/* Disable the button. */
$submit.attr("disabled", true);
});
});
</script>
PHP CODE:
<?php
$myemail = 'mymail#mail.com';//<-----Put Your email address here.
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "Contact Form Emocool Website ".
" Here are the details:\n Name: $name \n Telefono: $phone \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
if(mail($to,$email_subject,$email_body,$headers))
{
echo "Thank you for contacting us";
}
//redirect to the 'thank you' page
else
{
echo "Sorry, there has been an error";
}
?>
So the problem is when I hit the submit button, instead of the result showing inside the #contactResponse div, it is showing inside new page of the script contact-form-handler.php
Any suggestions why this is not working?
My best guess is that you are adding your #contactForm submit listener before the form is actually rendered. Try wrapping your jQuery in $(document).ready(function () {});
I don't see any other issues.
Using <script type="text/javascript"> , your script will not work, replace <script type="text/javascript"> with <script language="javascript">, It will work correctly. But language="javascript" is deprecated in favor of type="text/javascript". keep in mind you put the code $(document).ready(function(){ //code to be implemented// });
Anyhow your script will work by replacing type="text/javascript" with language="javascript"

Incorrect function on php script

I have a simple contact form I'm trying to implement but I'm getting an "incorrect function" error when I try to launch it. My code below is as follows, and when I click submit, it redirects to
http://mywebsite.com/contactme.php
but with the text "Incorrect function" and that's it. My debug on firefox shows the following error:
POST http://www.mywebsite.com/v/vspfiles/contactform/contactme.php [HTTP/1.1 405 Method Not Allowed 33ms]
13:54:52.368 The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range.
The character encoding of the page must be declared in the document or in the transfer protocol.
I am using volusion software if that helps. But I have no idea if the error is in my code or because my webhost won't allow the function. Can someone give me some insight? I have tried the "contactme.php" page with and without the doctype declared. My two files are below. I do not have an "error.htm" page.
contact.html:
<!DOCTYPE html>
<html>
<head>
<title>Contact</title>
</head>
<body >
<div id="contact-area">
<form method="post" action="/v/vspfiles/contactform/contactme.php">
<h3>Contact us</h3>
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
</div>
</body>
</html>
contactme.php:
<?php
$EmailFrom = "email#gmail.com";
$EmailTo = "email#gmail.com";
$Subject = "contact form";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// informs user they submitted, redirects to homepage
if ($success){
alert("Thank you for your interest in our multiple sample processing system. A member of the Claremont Bio team will respond to you shortly.");
window.location.assign(location.hostname);
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
alert("Thank you for your interest in our multiple sample processing system. A member of the Claremont Bio team will respond to you shortly.");
window.location.assign(location.hostname);
This is not valid php code, it is javascript. It definitely should not be in your php script.
As an alternative, in your if($success) condition you could redirect to a "success.php" page. For example:
if($success){
header("Location: http://www.mydomain.com/success.php");
}
An example of a contact.php page I use is as follows, note as per Jorge's comments, I make use of echoing the command...
<?php
// configuration
require("../includes/config.php");
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// submission is sanitised using the "query" function
$name = check_input($_POST["name"]);
$email = check_input($_POST["email"]);
$phone = check_input($_POST["phone"]);
$message = check_input($_POST["message"]);
$category = $_POST["category"];
switch($category)
{
// do some checking here
}
// insert user into db
// Success Message
$success = "
<div class=\"row-fluid\">
<div class=\"span11\">
<div class=\"alert alert-block alert-success\" id=\"thanks\">
<h4>Got it!</h4>
<br/>
<p>I'll be in touch within 24 hours. <strong> Promise.</strong></p>
<br/>
<p>In the meantime, why not check out my Facebook page...</p>
<br/>
www.facebook.com/myfacebooksite
</div>
</div>
</div>
";
$subject = 'New Website Message!';
$mailto = 'your#email.com';
// HTML for email to send submission details
$body = "
<br>
<p>The following information was submitted through the contact form on your website:</p>
<p><b>Name</b>: $name<br>
<b>Email</b>: $email<br>
<b>Phone</b>: $phone<br>
<b>Category</b>: $category<br>
<b>Message:</b>: $message<br>
";
$headers = "From: $name <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mailtext = "<html><body>$body</body></html>";
if (mail($mailto, $subject, $mailtext, $headers)) {
echo "$success"; // success
}
else
{
echo 'Form submission failed. Please try again...'; // failure
}
}
else
{
// else render form
redirect("/index.html");
}
?>
edit:
my contact form page has the following js:
// do the mailing
$('#contact_form').on('submit', function(e) {
e.preventDefault(); //Prevents default submit
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
$.ajax({
type: 'POST',
url: 'contact.php',
data: post_data,
success: function(msg) {
$(form).fadeOut(200, function(){
form.html(msg).fadeIn();
});
}
});
});
Hope that helps steer you...
So turns out this isn't my error, this is my webhost. Had to call them up and they told me they don't support PHP currently. so I'm off to rewrite this is javascript. I'll give the answer to Jason as his was the most technically correct and pointed out the error. Thanks guys.

Categories