Copy link to clipboard
Copied
I posted a script and was told that I needed to tell the scrip to pass along html. I have tried at least a dozen or so ways to do this with variations of these two lines but all attempts lead to the script bombing out and not sending anything through the process.
Here are the two lines I have been adding, I have tried a dozen variations with or without dots, \r\n, single quotes, double, etc.. Tried placing all of these variations above and at the end of the variables but every version I try bombs the script and I get no email. Can someone give me a pointer as to how to get this to send the html and still not stop the script. I know I am a rookie but if you read back you will see that I do spend hours reading and trying things before I come here. Hopefully I can get this thing to pass along the info I need so I can finish it up. Thanks, Scott.
Here are the two lines of code I have been dissembling and reassembling for the last two days:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Here is the script I have been working with:
<?php
$from="orderform@xxxxxxxxxxx.com";
$email="info@xxxxxxxxxx.com,['Sender']";
$subject=$_POST['Subject'];
$headers="Content-type: text/html";
$message=$_POST['']."
Company Name = ".$_POST['CompanyName']."
Company Address = ".$_POST['CompanyAddress']."
Company Phone = ".$_POST['CompanyPhone']."
Company Email = ".$_POST['CompanyEmail']."
Company Website = ".$_POST['URL']."
Contact Name = ".$_POST['ContactName']."
Contact Phone = ".$_POST['ContactPhone']."
Sender = ".$_POST['Sender']."
".$_POST['']."
Message from Sender = ".$_POST['Message']."
".$_POST['']."
RedWithGreenXXS = ".$_POST['RedGreenXXS']."
RedWithGreenXS = ".$_POST['RedGreenXS']."
RedWithGreenS = ".$_POST['RedGreenS']."
RedWithGreenM = ".$_POST['RedGreenM']."
RedWithGreenL = ".$_POST['RedGreenL']."
RedWithGreenXL = ".$_POST['RedGreenXL']."
RedWithGreenXXL = ".$_POST['RedGreenXXL']."
RedWithGreenXXXL = ".$_POST['RedGreenXXXL']."
RedWithBlueXXS = ".$_POST['RedBlueXXS']."
RedWithBlueXS = ".$_POST['RedBlueXS']."
RedWithBlueS = ".$_POST['RedBlueS']."
RedWithBlueM = ".$_POST['RedBlueM']."
RedWithBlueL = ".$_POST['RedBlueL']."
RedWithBlueXL = ".$_POST['RedBlueXL']."
RedWithBlueXXL = ".$_POST['RedBlueXXL']."
RedWithBlueXXXL = ".$_POST['RedBlueXXXL']."
RedWithWhiteXXS = ".$_POST['RedWhiteXXS']."
RedWithWhiteXS = ".$_POST['RedWhiteXS']."
RedWithWhiteS = ".$_POST['RedWhiteS']."
RedWithWhiteM = ".$_POST['RedWhiteM']."
RedWithWhiteL = ".$_POST['RedWhiteL']."
RedWithWhiteXL = ".$_POST['RedWhiteXL']."
RedWithWhiteXXL = ".$_POST['RedWhiteXXL']."
RedWithWhiteXXXL = ".$_POST['RedWhiteXXXL'];
mail ( $email, $subject, $message, $headers, "From:".$from );
Print "your message has been sent";
?>
Thanks again for your continued support. Scott
I don't use PHP mail. I use swiftmailer, which is an open source PHP mail class. But some time ago I created the following script that uses PHP mail. Paste the whole thing into a new file and name it contact.php, then run it. The script includes comments that explain what's going on.
In the code you have provided today, it isn't HTML, so it doesn't need to be sent as content type HRTML. Just add line breaks to your list of items (\n).
<?php
// Be sure to change the value of $to to your own email a
Copy link to clipboard
Copied
I have made some progress, this version works but it sends the info as an attachment with a blank page for the body of the message.
<?php
$email="info@xxxxxxxxxxx.com,['Sender']";
$subject=$_POST['Subject'];
$headers='Content-type: text/html\r\n';
$message=$_POST['']."
Company Name = ".$_POST['CompanyName']."
Company Address = ".$_POST['CompanyAddress']."
Company Phone = ".$_POST['CompanyPhone']."
Company Email = ".$_POST['CompanyEmail']."
Company Website = ".$_POST['URL']."
Contact Name = ".$_POST['ContactName']."
Contact Phone = ".$_POST['ContactPhone']."
Sender = ".$_POST['Sender']."
".$_POST['']."
Message from Sender = ".$_POST['Message']."
".$_POST['']."
RedWithGreenXXS = ".$_POST['RedGreenXXS']."
RedWithGreenXS = ".$_POST['RedGreenXS']."
RedWithGreenS = ".$_POST['RedGreenS']."
RedWithGreenM = ".$_POST['RedGreenM']."
RedWithGreenL = ".$_POST['RedGreenL']."
RedWithGreenXL = ".$_POST['RedGreenXL']."
RedWithGreenXXL = ".$_POST['RedGreenXXL']."
RedWithGreenXXXL = ".$_POST['RedGreenXXXL']."
RedWithBlueXXS = ".$_POST['RedBlueXXS']."
RedWithBlueXS = ".$_POST['RedBlueXS']."
RedWithBlueS = ".$_POST['RedBlueS']."
RedWithBlueM = ".$_POST['RedBlueM']."
RedWithBlueL = ".$_POST['RedBlueL']."
RedWithBlueXL = ".$_POST['RedBlueXL']."
RedWithBlueXXL = ".$_POST['RedBlueXXL']."
RedWithBlueXXXL = ".$_POST['RedBlueXXXL']."
RedWithWhiteXXS = ".$_POST['RedWhiteXXS']."
RedWithWhiteXS = ".$_POST['RedWhiteXS']."
RedWithWhiteS = ".$_POST['RedWhiteS']."
RedWithWhiteM = ".$_POST['RedWhiteM']."
RedWithWhiteL = ".$_POST['RedWhiteL']."
RedWithWhiteXL = ".$_POST['RedWhiteXL']."
RedWithWhiteXXL = ".$_POST['RedWhiteXXL']."
RedWithWhiteXXXL = ".$_POST['RedWhiteXXXL'];
mail ( $email, $subject, $message, $headers);
Print "your message has been sent";
?>
I took out the "$from" variable and the .from in the email function.
Driving me crazy. Got it to work once but the email came in very late and I thought it was still not sending so I moved along and lost the backup.. Thanks for your help, Scott
Copy link to clipboard
Copied
I don't use PHP mail. I use swiftmailer, which is an open source PHP mail class. But some time ago I created the following script that uses PHP mail. Paste the whole thing into a new file and name it contact.php, then run it. The script includes comments that explain what's going on.
In the code you have provided today, it isn't HTML, so it doesn't need to be sent as content type HRTML. Just add line breaks to your list of items (\n).
<?php
// Be sure to change the value of $to to your own email address
// Be sure to name the file contact.php
// the next line only runs the processing script if the form has been submitted.
// the next line makes sure the email address is actually an email address
// The "!" at the beginning means do the following if the email address is NOT true. Remove the "!" and it would mean IF IS TRUE
if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)){
$message="Please provide a correct email address";} else {
// strip_tags is a PHP function that removes all tags from a block of text. For instance harmful script could be injected in the form fields by a hacker. strip_tags will remove such scripts.
$name = strip_tags($_POST['name']);
$company_name = strip_tags($_POST['company_name']);
$telephone = strip_tags($_POST['telephone']);
$email = $_POST['email'];
$comments = strip_tags($_POST['comments']);
$to = 'your@emailaddress.com';
$subject = 'Contact form submitted.';
$body = $name. "\n" .$comments;
$headers = 'From: ' .$email;
// This is the line that actually mails the form data. The PHP function is simply mail(). The function needs to know:
// who to send to
// what the subject line should be
// what the email should consist of
// headers can include various info, but in this case just includes the email address of the sender
// Note that if the email does not send, a message is returned to notify the user of the failure.
if (mail($to, $subject, $body, $headers)) {
echo 'Thanks for contacting us. We\'ll be in touch soon!';
} else {
$message = 'Sorry an error occurred. Please try again later.';
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php echo "<p style='color:red'>$message</p>"; ?>
<div class="contact_form">
<form id="contactform" action="contact.php" method="post">
<p>Name:<br/><input name="name" type="text" required /></p>
<p>Company Name: <br/><input name="company_name" type="text" required/></p>
<p>Telephone: <br/><input name="telephone" type="tel" required/></p>
<p>Email: <br/><input name="email" type="email" required/></p>
<p>Comments: <br/><textarea name="comments" required/> </textarea></p>
<input type="submit" name="submit" value="Send!"/>
</form>
</div>
</body>
</html>
Copy link to clipboard
Copied
Again I would like to thank you for all of your help in several of these posts while I have been working on this script, I also appreciate the explanations you provide as they usually lead me in the right direction.
In case I wasn't clear above (new to this format) what I am trying to do is get my script to deliver an email with each variable on it's own line. This works as long as I don't put any numbers in the top of the form in the text fields, if I do put any numbers there the email output runs the variables together into one long paragraph. Note however, this behavior only effects the output above the two empty spaces I added by putting in (".$_POST['']."). After that the variables for the rest of the script say on their own lines.
I have to admit, about three hours ago I stumbled on the right combination of dots, colons and such and had two of the emails come through perfectly, with numbers in the address and real information all along, each item on separate lines instead of running all together but somehow in my haste and being tired I moved along without a proper backup and a few minutes later when the email came through I realized I had the correct syntax but could not recover it. So frustrating but I might pick it up again at some point. For now I am going to tear into the script you sent me and see what I can learn from it. Thanks again, Scott
Copy link to clipboard
Copied
OK, here's something that might help regarding the issue you mentioned of getting the configuration of double quotes, single quotes, periods and semicolons right : At the top of the processing script, add. . .
extract($_POST);
. . .then, instead of . . .
Company Phone = ".$_POST['CompanyPhone']."\n
. . .you can have. . .
Company Phone = $CompanyPhone\n
. . .Put all the message content in a single variable wrapped in a single pair of double quotes.
Weren't you using table cells at one point? That's why I recommended adding content type text/html. If you are not using any html tags, then just use \n for line breaks.