I have created a contact me page that uses CK Editor to edit the content of the mail. I am using xampp/ localhost to test the mail. I want the mail to be exactly like i edit it in the editor
For example the bold part in editor doesnot show up bold in the mail it is sent as
<strong>SOMETHING IN BOLD</strong>
How do i use CK editor or any other so that the mail is sent as
SOMETHING IN BOLD
and not as shown above.
Thank you.
HTML Code
<form action="upload.php" method="post" style="height:100%">
<input name="articleTitle" value="Title" maxlength="50"
id="articleTitle">
<textarea name="article-body">
Compose your article...
</textarea>
<script>
CKEDITOR.inline( 'article-body' );
</script>
<br>
<input name="senderName" type="text" value="Name" maxlength="50"
id="name" class="textBox">
<input name="senderEmail" value="Email address" maxlength="50"
id="email" class="textBox">
<input name="abtyou" value="About Yourself" maxlength="150"
id="abtyou" class="textBox">
<input type="submit" name="submit" class="button">
</form>
PHP Code
<?php
$thankYou="";
if(isset($_POST["submit"])) {
$recipient="zain.farid#live.com";
$subject="New Guest Post";
$sender=$_POST["senderName"];
$senderEmail=$_POST["senderEmail"];
$senderAbout=$_POST["abtyou"];
$message=$_POST["article-body"];
$title=$_POST["articleTitle"];
$mailBody="Name: $sender\nEmail: $senderEmail\nAbout Sender: $senderAbout\nTitle: $title\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="Thank you! Your post has been submitted.";
}
?>
Looks like you're not sending an HTML-header with the email. Here you can see how you can do this: (example 3) http://www.w3schools.com/php/func_mail_mail.asp
<?php
if(isset($_POST["submit"])) {
// ... email settings ...
// 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";
$headers .= "From: $sender <$senderEmail>" . "\r\n";
mail($recipient, $subject, $mailBody, $headers);
// ...
}
?>
Related
I've an HTML contact form and I want to use it in my footer, but I don't know how to do it!!
Here is my form:
<div class="footer-right">
<p>Contact Us</p>
<form action="#" method="post">
<input type="text" name="email" placeholder="Email" />
<textarea name="message" placeholder="Message"></textarea>
<button>Send</button>
</form>
</div>
The <button> tag will not submit the form. You should change it to: <button type="submit">Send</button>
For handling the form you could add something like this in the beginning of your file::
<?
//Mail sending function
$subject = "Web Form";
$from = $_POST['email'];
$to = "youremail#example.com";
//data
$msg = $_POST['message'];
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
mail($to,$subject,$msg,$headers);
echo "Mail Sent.";
?>
Since you tagged it as PHP, this answer will get you started.
Change:
<button>Send</button>
to:
<input type="submit" value="Send">
Change:
<form action="#" method="post">
to:
<form action="mailer.php" method="post">
Create a file named mailer.php and place it in the same folder as the filename of the document you presented, and in that file, add the following contents:
<?php
$recipient="receipient#example.com";
$subject="new message from ".$_POST['email']." - contact form";
$message=$_POST['message'];
mail($recipient, $subject, $message);
?>
<p>Your message has been sent.</p>
Note that you should add custom HTML between the last two lines of the above code or your HTML won't validate with W3C standards.
I've written a simple PHP HTML email form. That's all fine, it sends the email, the email doesn't get blocked. The problem with it is that only certain mail clients are receiving the emails: Gmail gets them fine, but another email account (used through a webmail client) doesn't, and neither do email apps I try. It appeared to work for a while after adding an X-Mailer header, but then stopped again; it also worked briefly when the recipients line was strangely formatted deliberately.
The form:
<form name="email" action="send.php" method="POST" id="mailform">
* From: <input type="text" name="from" required/><br/>
* To: <input type="text" name="to" required/><br/>
* Reply-To: <input type="text" name="reply" required/><br/>
Subject: <input type="text" name="subject" /><br/>
* Message:<br/>
<textarea name="email" rows="10" cols="100" id="message" required></textarea><br/>
<input type="button" name="convert" id="convert" value="Convert and Check" />
</form>
(the 'Convert and Check' button is there because I use Markdown to format the HTML email; that part is again working fine. It changes to a Send button once the MD is converted to HTML.)
The PHP:
$from = $_POST["from"];
$to = $_POST["to"];
$reply = $_POST["reply"];
$subject = $_POST["subject"];
$message = $_POST["email"];
$headers = "Content-Type: text/html" . "\r\n"
. "Reply-To: ".$reply . "\r\n"
. "From: ".$from . "\r\n"
. "X-Mailer: PHP/".phpversion() . "\r\n";
echo "<h3>Preview</h3><div class='content-container'>";
echo "<b>To:</b> ".htmlspecialchars($to)."<br/>";
echo "<b>Headers:</b> ".htmlspecialchars($headers)."<br/><hr/>";
echo "<div class='frame'>".$message."</div></div>";
echo "<br/><h3>Status</h3>";
$send = mail($to, $subject, $message, $headers);
if($send) {
echo "Your mail was successfully accepted for delivery.";
}
else {
echo "Sending of the email failed.";
}
Any ideas? It's got me confused - why do only some clients receive this?
because most of the email providers block emails from dynamic ips.
I have a HTML form with 4 id (name, email, message, subject), a js with all the variables declared and a PHP that should send the mail.
HTML
<form id="formail" method="post" action="">
<input type="text" id="nome" name="nome" value="" size="22" /><br />
<input type="text" id="email" name="email" value="" size="54" /><br />
<textarea id="messaggio" name="messaggio" rows="1" cols="55" style="resize: none;"></textarea><br />
<input type="text" id="subject" name="subject" value="" size="22" /><br />
<input type="submit" id="send" name="send" value="" style="cursor: pointer"/>
<br />
<div id="answer"></div>
</form>
This is the js
var valid = '';
var isr = ' requested.</h6>';
var name = $("#nome").val();
var mail = $("#email").val();
var subject = $("#subject").val();
var messaggio = $("#messaggio").val();
(follow controls about the name and mail, and the send function)
This is the php
$mail = trim($_POST['mail']);
$name = $_POST['name'];
$text = $_POST['messaggio'];
$subject = $_POST['subject'];
$ip = $_SERVER['REMOTE_ADDR'];
$to = "admin#test.com";
$message = "Username: ".$name.", ".$mail.".<br />";
$message .= "Subject: ".$subject.".<br />";
$message .= "Messaggio: <br />".$text."<br /><br />";
$message .= "IP: ".$ip."<br />";
$headers = "From: ".$mail." \r\n";
$headers .= "Reply-To: ".$mail." \r\n";
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 \n";
if(mail($to, $subject, $message, $headers)){
echo "<h6>Message sent!</h6>";
}
I posted only the relevant code. When I click send I'll receive the mail, however the field "subject" is blank, as if the variables "subject" had been ignored.
Could you please help me? I'm starting to learn PHP but I'm still a newbie. Thank you.
Where is your mail function?
use following mail function:
mail($to-mail,$subject,$message,$header);
Two key points here:
a) Not sure exactly what function you're using to actually send the mail, but assuming PHP mail() you will need to use the $subject as the second parameter.
b) If you publish this on the open web you will be exploited as an open relay by spammers.
The attack you are vulnerable to is called 'header injection'.
In short, if I submit my 'mail' value as myemail#example.org%0ABcc:poorsap#example.com the script will add an extra line (the %0A is a linefeed), and submit to mail() with an extra Bcc header for however many emails I like (in this case poorsap#example.org).
Please take a read through this: http://www.securephpwiki.com/index.php/Email_Injection and consider using an alternate library to avoid this problem.
I have a "tell a friend" pop up email form that allows users to share my page with an email address that they enter. It pops up fine, but I can't get the form to send the email.
html:
<div id="tellfriend">
Close
<form id='tellafriend_form' method="post" action="#sendMessage" name="tellafriend_form">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name" />
<label for="to">Friend's email:</label>
<input type="text" id="to" name="to" />
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" />
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" name="submit" value="Submit">
</form>
</div><!-- #tellfriend -->
javascript that handles the "pop up":
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script>
$(function() {
$('#tellfriend').hide();
$('#sendMessage').click(function(e) {
$("#tellfriend").fadeToggle('fast');
});
});
</script>
php that's supposed to send the mail:
<?
if (isset($_POST['Submit'])) {
// This will check to see if the form has been submitted
$senders_name = $_POST['name'];
// The person who is submitting the form
$recipient_friend = $_POST['to'];
// The forms recipient
$subject = $_POST['subject'];
// The subject line
$message = $_POST['message'];
// The message being sent
mail($recipient_friend, "From $senders_name", $subject, $message);
if (isset($_POST['your_email'])) {
echo "<br>Your friend has been contacted <br><br>Thank you $senders_name";
}}
?>
Disclaimer: PHP newbie, hoping to learn. Thanks!
The order of your parameters in mail function is not correct. see this
it should be
mail($recipient_friend, $subject, $message);
if you want to use headers then do this
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$recipient_friend.' <'.$recipient_friend.'>' . "\r\n";
$headers .= 'From: '.$sender.' <'.$senderEM.'>' . "\r\n";
Then call mail like this
mail($recipient_friend, $subject, $message, $headers);
You have one error in your PHP code:
if (isset($_POST['Submit'])) {
should be:
if (isset($_POST['submit'])) {
with a lowercase "s".
Indeed the name of you submit button is "submit" but the value is "Submit".
You could eventually do that:
if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') {
And your mail parameters are not correct like boug said.
You have 2 errors
first:
if (isset($_POST['submit']))
// $_POST is case sensitive
second:
if (isset($_POST['your_email']))
// you dont have an inout named 'your_email'
I have a contact form on a page that sends the details of the form to an email address. You can view it here, www.wonder.ie
The HTML for the form is the following:
<form id="form" name="form27" class="wufoo page" enctype="multipart/form-data" method="post" action="mailer.php">
<ul>
<li id="foli1">
<label class="op" id="title1" for="Field1">Name</label>
<div><input id="Field1" name="name" type="text" class="op required" value="" maxlength="255" tabindex="1" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
</li>
<li id="foli2">
<label class="op" id="title2" for="Field2">Email</label>
<div><input id="Field2" name="email" type="text" class="op required email" value="" maxlength="255" tabindex="2" onkeyup="handleInput(this);" onchange="handleInput(this);" /></div>
</li>
<li id="foli3">
<label class="op" id="title3" for="Field3">Inquiry</label>
<div><textarea id="Field3" name="message" class="op required" rows="10" cols="50" tabindex="3" onkeyup="handleInput(this);" onchange="handleInput(this);"></textarea></div>
</li>
</ul>
<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />
</form>
And for my PHP it is this:
<?php
if(isset($_POST['submit'])) {
$to = "AN_EMAIL#ADDRESS.COM";
$subject = "Email from Wonder.ie";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Does everything look correct? I know I have the form names matched correctly with the PHP but I can't figure out why I'm not receiving the email you know - FYI the PHP on the site has a real email address, not AN_EMAIL#ADDRESS.COM. Once I hit the submit button I am taken to mailer.php but I notice the echo "blarg!" so my guess is the email is not being sent.
Thank you!
You should change
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
Try changing
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
This is because $_POST looks for the name of a form input, not the type.
If nothing above helps, try and see if you can debug the code.
Catching PHP mail() errors and showing reasonable user error message
In your PHP code you check if $_POST['submit'] is set, but in your HTML code you gave the submit button the name of saveForm so you should change the line
if(isset($_POST['submit'])) {
to
if(isset($_POST['saveForm'])) {
Hope this helped you :)
Some email servers won't accept emails without appropriate headers and you haven't provided any. This is what I use.
http://us2.php.net/manual/en/function.mail.php
$header = "From: ".$fromText."\r\n";
$header .= "Cc: ".$ccText."\n";
$header .= "Reply-To : ".$fromText."\r\n";
$header .= "Return-Path : ".$fromText."\r\n";
$header .= "X-Mailer: PHP\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
you are using
if(isset($_POST['submit'])) { but, you have save the submit button name assaveForm So, use if(isset($_POST['saveForm'])) {
your problem is it's pour out blarg.
it's definitely the post does not reach your
code->
mail($to, $subject, $body);
and the name of the submit should be changed to
'saveForm'
by the way :)..
just tried
mail($to, $subject, $body);
in your x.php , upload it and chage to , subject and body to right things
and if it's sent then the mail function works okay.
if(#mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
this is also a good code I have found in stackoverflow
to check if mail function works.
In your html your have
<input id="button" name="saveForm" class="btTxt submit" type="submit" value="Submit" />
but in the php file when you check for $_POST["submit"], which is not right.
You need to change if(isset($_POST['submit'])) to if(isset($_POST['saveForm']))
or if(isset($_POST['submit'])) to if(isset($_POST))
HTML form mail sending guide in PHP http://top-answers.net/webhost/web-hosting.html