I have a web form which emails the form content back to me using the phpmailer function. I'm trying to add an AddAttachment feature but I seems to have an issue in the php.
This is my html snippet:
<td>
<div align="right">Add attachment :</div>
</td>
<td colspan="2">
<input type="file" name="uploaded_file" id="uploaded_file" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
</td>
And this is my php;
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mailer.********.local"; // SMTP server
$mail->From = $_POST['email'];
$mail->AddAddress("frank********#gmail.com");
$mail->Subject = "Request for Contract Registration for " . $_POST['name'];
$mail->Body = "Supplier number : " . $_POST['suppno'] . "\r\n";
$mail->Body .= "Payee name : " . $_POST['name'] . "\r\n";
$mail->Body .= "Address : " . $_POST['add'] . "\r\n";
$mail->Body .= " : " . $_POST['add2'] . "\r\n";
$mail->Body .= " : " . $_POST['add3'] . "\r\n";
$mail->Body .= "Nature of business : " . $_POST['nob'] . "\r\n";
$mail->Body .= "Tax Ref : " . $_POST['rctref'] . "\r\n";
$mail->Body .= "Description of works : " . $_POST['descofwks'] . "\r\n";
$mail->Body .= "Start date of contract : " . $_POST['stdte'] . "\r\n";
$mail->Body .= "End date of contract : " . $_POST['enddte'] . "\r\n";
$mail->Body .= "Location of contract : " . $_POST['location'] . "\r\n";
$mail->Body .= "Estimated value of contract : " . $_POST['contractval'] . "\r\n";
$mail->Body .= "Confirm contract : " . $_POST['confirm'] . "\r\n";
$mail->Body .= "Declaration : " . $_POST['declaration'] . "\r\n";
$mail->Body .= "Department : " . $_POST['dept'] . "\r\n";
$mail->AddAttachment($_POST['uploaded_file']);
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
header('Location: confirm.htm');
}
?>
Is there an issue with my path??? It's probally something simple that I'm missing but if anyone can help me I'd greatly appreciate it!
Thanking you in advance,
Frank.
Instead of using
$mail->AddAttachment($_POST['uploaded_file']); // WRONG
try this
if (isset($_FILES['uploaded_file']) &&
$_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
$_FILES['uploaded_file']['name']);
}
Uploaded files are stored in the temp folder.
You should add the attachment from the filesystem, it is a mistake to use $_POST for this.
Related
I have PHPmailer library. This is a code which is a password reminder, when you add your email to input, it will send your forgotten password to your email. This code only sends through php mail, but since my host does not allow it, only option would be to use SMTP, right? So this is the php code with form:
<div class="tab-pane fade <?php
if ($tab == 'ForgotPass') {
echo 'active in';
}
?>" id="forgotpass">
<form role="form2" action="index?tab=ForgotPass" method="POST">
<fieldset>
<?php
#$_SESSION['email'] = $_POST['email'];
?>
<hr class="colorgraph">
<div class="form-group">
<input type="email" name="email" maxlength="64" id="email" class="form-control input-lg" placeholder="El. paštas" value="<?= $_SESSION['email'] ?>" required>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<input type="submit" name="forgot" class="btn btn-lg btn-success btn-block" value="send">
</div>
</div>
</fieldset>
</form>
<?php
if (isset($_POST['forgot'])) {
$email = $_POST['email'];
if (empty($email)) {
echo errorbox("Please enter email.");
} else {
$check = mysql_query("SELECT * FROM users WHERE email='$email'");
$row2 = mysql_fetch_assoc($check);
if (mysql_num_rows($check) > 0) {
$query = mysql_query("SELECT * FROM settings");
$row = mysql_fetch_assoc($query);
$subject = 'Forgot Password - ' . $row['title'] . '';
$message = '
<center>
<a href="' . $row['url'] . '" title="Visit ' . $row['url'] . '" target="_blank">
<h1><img src="' . $row['url'] . '' . $row['logo'] . '" title="' . $row['title'] . '"> ' . $row['title'] . '</h1>
</a><br />
<b>Registration details:</b><br />
Username: ' . $row2['username'] . '<b></b><br />
Password: ' . $row2['password'] . '<b></b><br />
</center>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: ' . $email . ' <' . $email . '>' . "\r\n";
$headers .= 'From: ' . $row['email'] . ' <' . $row['email'] . '>' . "\r\n";
#mail($to, $subject, $message, $headers);
echo okbox("We have just sent you your forgotten data from your account on the entered E-Mail Address");
} else {
echo errorbox("There is no player with such email.");
}
}
}
?>
AND i also have this SMTP configured code which just sends a message to test email and I already tested, it works, it does send the message, now I have to somehow make it so that it would send the password to user email:
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.website.com";
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->Port = 25;
$mail->Username = "support#website.com";
$mail->Password = "emailpass";
$mail->From = "support#website.com";
$mail->FromName = "Test User";
$mail->AddAddress("emailthatgetsmessage#gmail.com");
//$mail->AddReplyTo("mail#mail.com");
$mail->IsHTML(true);
$mail->Subject = "Test message from server via SMTP Authentication";
$mail->Body = "Test Mail sent via SMTP Authentication";
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
I have my form setup and working perfect, however I need to add attachment functionality (only) to this. I've reviewed several threads and tried implementing but with no luck.
I'm trying to add id='file-7'
HTML code:
<fieldset class="clean">
<textarea name="comments" id="comments" placeholder="Message*"></textarea>
</fieldset>
<fieldset class="percent-one-full">
<div class="box">
<input type="file" name="file-7[]" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple />
<label for="file-7"><span></span> <strong><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> Upload file…</strong></label>
<input name="send" type="submit" class="button red" id="submit" onClick="MM_validateForm('name','','R','bandname','','R', 'email','','RisEmail','comments','','R');return document.MM_returnValue" value="SEND"/>
JS code:
jQuery(document).ready(function(){
$('#cform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.after('<img src="images/nivo-preloader.gif" class="contact-loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
bandname: $('#bandname').val(),
osflow: $('#osflow').val(),
hiddenDiv: $('#hiddenDiv').val(),
hiddenDivv: $('#hiddenDivv').val(),
hiddenDivvv: $('#hiddenDivvv').val(),
hiddenDivvvv: $('#hiddenDivvvv').val(),
hiddenDivvvvv: $('#hiddenDivvvvv').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#cform img.contact-loader').fadeOut('slow',function(){$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#cform').slideUp('slow');
}
);
});
return false;
});
});
PHP code:
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
print_r($_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$_POST['bandname'];
$_POST['osflow'];
$_POST['hiddenDiv'];
$_POST['hiddenDivv'];
$_POST['hiddenDivvv'];
$_POST['hiddenDivvvv'];
$_POST['hiddenDivvvvv'];
$comments = $_POST['comments'];
//$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Please enter your message.</div>';
exit();
//} else if(!isset($verify) || trim($verify) == '') {
// echo '<div class="error_message">Please enter the verification number. </div>';
// exit();
//} else if(trim($verify) != '4') {
// echo '<div class="error_message">The verification number you entered is incorrect.</div>';
// exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "example#example.net";
$address = "info#example.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Decal Inquiry from ' . $name . '';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name. The additional message is as follows." . PHP_EOL . PHP_EOL;
$e_body = "Name: $name" . PHP_EOL . "\r\n";
$e_body2 = "Email: $email" . PHP_EOL . "\r\n";
$e_custom = "Band Name: $bandname" . PHP_EOL . "\r\n";
$e_custom2 = "Interest In: $osflow" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Size: $hiddenDiv" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Head Color: $hiddenDivv" . PHP_EOL . "\r\n";
$e_custom4 = "Mic Port Position: $hiddenDivvv" . PHP_EOL . "\r\n";
$e_custom5 = "Banner Color: $hiddenDivvvv" . PHP_EOL . "\r\n";
$e_custom6 = "Banner Size: $hiddenDivvvvv" . PHP_EOL . "\r\n";
$e_content .="Content-Disposition: attachment; filename=$file-7" . "\r\n";
$e_content = "Comments: $comments" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email at $email.";
$msg = wordwrap( $e_body . $e_body2 . $e_custom . $e_custom2 . $e_custom3 . $e_custom4 . $e_custom5 . $e_custom6 . $e_custom7 . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, we've received your inquiry and will be in touch shortly.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
Any help would be much appreciated!
I am trying to get a PHP email to send in an HTML format, but the current email is just sending in code. I am not sure at all what I am doing wrong.
Does anyone see anything?
ini_set('display_errors', 1);
error_reporting(E_ALL);
$project_name = $_POST['project_name'];
$title_roll = $_POST['title_roll'];
$project_email = $_POST['project_email'];
$project_number = $_POST['project_number'];
$project_description = $_POST['project_description'];
$project_source = $_POST['project_source'];
$project_socialMedia = $_POST['project_socialMedia'];
$project_humanTest = $_POST['project_humanTest'];
$to = 'email';
$subject = 'Project Inquiry Form Sent';
//$message = 'FROM: '.$project_name. "<br>" . ' Email: '.$project_email. "<br>" . 'Message: '.$project_description;
//$msgcontents = "Name: $project_name<br>Email: $project_email<br>Message: $project_description";
$message = '
<html>
<head>
<title>Project Inquiry Form Sent</title>
</head>
<body>
<p>Hi Optimum Designs Team,</p><br>
<p>There has been a Project submitted. Here are the details:</p><br>
<p>Name: '. $project_name .'</p>
<p>Name: '. $title_roll .'</p>
<p>Name: '. $project_email .'</p>
<p>Name: '. $project_number .'</p>
<p>Name: '. $project_description .'</p>
<p>Name: '. $project_source .'</p>
<p>Name: '. $project_socialMedia .'</p><br>
<p>Good Luck,</p>
<p>Administration</p>
</body>
</html>
';
// 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";
$headers = 'From:' .$project_email . "\r\n";
if (!empty($project_email)) {
if (filter_var($project_email, FILTER_VALIDATE_EMAIL)) {
//Should also do a check on the mail function
if (mail($to, $subject, $message, $headers)) {
echo "Your email was sent!"; // success message
} else {
echo "Mail could not be sent!"; // failed message
}
} else {
//Invalid email
echo "Invalid Email, please provide a valid email address.";
}
} else {
echo "Email Address was not filled out.";
}
That's because your last header
$headers = 'From:' .$project_email . "\r\n";
is missing its concatenate
$headers .= 'From:' .$project_email . "\r\n";
^ right there
in turn breaking the chainlink.
I would like to know why can't I receive the check-box value in my PHP email sender?
Here is the html:
<form method="post" action="send.php" name="cform" id="cform" class="form-signin" role="form">
<input name="name" id="name" type="text" class="form-control" placeholder="Your name and surname..." >
<input name="email" id="email" type="email" class="form-control" placeholder="Your email address..." >
<textarea name="comments" id="comments" class="form-control" placeholder="Your request..."></textarea>
<p>
<input type="checkbox" name="newsletter" id="newsletter" value="Yes" checked>
<span>I would like to receive the newsletter</span>
</p>
<input type="submit" id="submit" name="submit" class="lightButton" value="Submit >">
<div id="simple-msg"></div>
</form>
And here's the relevant part of the PHP code I found on the Internet ( don't know if here or in a blog, I'm kind of new to PHP so I can't do it from scratch ) and modified to my needs.
<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$x_newsletter = $_POST['newsletter'];
$address = "xxx#gmail.com";
$e_subject = 'Richiesta contatto da ' . $name . '.';
$e_body = "Richiesta contatto da parte di $name:" . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_checkNl = "Inviare newsletter: $x_newsletter" . PHP_EOL . PHP_EOL;
$e_reply = "$name\n$email";
$msg = wordwrap( $e_body . $e_content . $e_checkNl . $x_newsletter . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
?>
I put the $x_newsletter variable to catch the check-box "Yes" value (or at least something like 0 or 1), and later in the code a $e_checkNl that would write the value in the mail.
Fact is that it is a week that I'm searching in stack-overflow for and answer and troubleshooting this PHP trying to figure this thing out but every email I receive from the PHP sender lacks of this important information.
I don't really know, it could be a typo, or some sort of syntax that I can't manage as a newbie, but it's driving me crazy.
Can you please help me?
I'm here should you need any other kind of information.
Thank you,
Nico
EDIT:
here is the full PHP page. Every "if" i put I always get a "NO" option that is totally weird...
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
print_r($_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$x_newsletter = $_POST['newsletter'];
if(trim($name) == '') {
echo '<div class="error_message">Your name is required</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Insert valid email address</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Invalid email address. Please retry. </div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Insert your messagge.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "xxx#gmail.com";
$e_subject = 'Richiesta contatto da ' . $name . '.';
$e_body = "Richiesta contatto da parte di $name:" . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
//checkbox
$e_checkNl = "Inviare newsletter: $x_newsletter" . PHP_EOL . PHP_EOL;
$e_reply = "$name\n$email";
$msg = wordwrap( $e_body . $e_content . $e_checkNl . $x_newsletter . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3>Request sent successfully</h3>";
echo "<p>Dear <strong>$name</strong>, Your request has been received, we will contact you as soon as possible.</p><p>Grazie,<br/>Top Italy Travel.</p>";
echo "<p>$e_checkNl</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERRORE!';
}
But the last part makes the form show a div on page for successful or error request, while the first part is a simple form check.
I doubt those cause this issue.
This will give you your desired result:
Replace $x_newsletter = $_POST['newsletter']; with:
$x_newsletter = (isset($_POST['newsletter'])) ? $_POST['newsletter'] : 'No';
I have a php form with <meta charset="utf-8" /> (I also tried with <meta charset="ISO-8859-1" /> which give me the same result)
When I test my form with the characters " and ', the email I receive transform those characters into their ASCII characters :
Subject: \"\'
Message: \"\'
Sent by: \"\'
(Somehow, the subject field only adds a \ before the characters)
I have also noticed that anything in between < and > are stripped out in $formAuthor and $formContent but not in $formSubject
Also if the from is submitted with a error in the captcha, the form keep in memory what was written in the field but anything after " in the $formAuthor and $formSubject is stripped out but not in $formContent (it's weird because it does follow the same logic than the one of the email issue)
It's not a server issue because I only have this problem with this form, not with the others once I have.
Thanks a lot for your help !
here is the some part of the php form :
// if all the fields have been entered correctly and there are no recaptcha errors build an email message
if (($resp->is_valid) && (!isset($hasError))) {
$emailTo = 'contact#website.com'; // here you must enter the email address you want the email sent to
$subject = 'Message from: ' . $formAuthor . ' | ' . $formSubject; // This is how the subject of the email will look like
$body = "Email: $formEmail \n\nSubject: $formSubject \n\nMessage: $formContent \n\nSent by: $formAuthor";// This is the body of the email
$headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers
//send email
mail($emailTo, $subject, $body, $headers);
// set a variable that confirms that an email has been sent
$emailSent = true;
}
$emailSent = true;
}
// if there are errors in captcha fields set an error variable
if (!($resp->is_valid)){
$captchaErrorMsg = true;
}
}
} ?>
here is the HTML :
<div id="singleParagraphInputs">
<div>
<label for="formAuthor">Name</label>
<input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>" size="40" />
</div>
<div>
<label for="formEmail">Email</label>
<input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="40" />
</div>
<div>
<label for="formSubject">Subject</label>
<input type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="40" />
</div>
<div id="commentTxt">
<label for="formContent">Message</label>
<textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="40" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea>
</div>
Try this
$emailTo = 'contact#website.com';
$subject = "Message from: " . ' <'. $formEmail .'> ' . "|" . ' <'. $formSubject .'> ';
$body = "Email: " . ' <'. $formEmail .'> ' . "\n\n Subject: " . ' <'. $formSubject .'> ' . "\n\n Message: " . ' <'. $formContent .'> ' . "\n\n Sent by: " . ' <'. $formAuthor .'> ';
// Body alternative $body = "Email: " . ' <'. $formEmail .'> ' . "\n\n" . " Subject: " . ' <'. $formSubject .'> ' . "\n\n" . "Message: " . ' <'. $formContent .'> ' . "\n\n" . "Sent by: " . ' <'. $formAuthor .'> ';
$headers = "From: " . ' <'. $formEmail .'> ' . "\r\n";
$headers .= "Reply-To: " . ' <'. $formEmail .'> ' . "\r\n";
$headers .= "Return-Path: " . ' <'. $formEmail .'> ' . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=utf-8" . "\r\n";
$mail = mail($emailTo, $subject, $body, $headers);
if($mail) {
// If success
}
else {
// If fail
}