Can anyone think of a logical reason to why a contact form which works perfectly well on my 123 reg account, will not work on my clients account? when I test it on my side, I get the email and the form contents through to my inbox perfectly but when the same codes are used on my clients account, with his email address, he receives an email with no data..
<?php
$EmailFrom = "webmaster#pb.co.uk";
$EmailTo = "loans#website.co.uk";
$Subject = "Testing";
$Name = Trim(stripslashes($_POST['Name']));
$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 .= "eMail: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://website/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
change
"From: $EmailFrom"
to
"From: $EmailFrom" . "\r\n"
Add header.
$Body = 'MIME-Version: 1.0' . "\r\n";
$Body .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$Body .= 'From: '. $EmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion();
Related
I need to attach Outlook calendar file (.ics) to the email with mail function.
This is what I have now, but it is not working.
<?php
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$companyname = $_POST["company"];
$file = "webinar-041016.ics";
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$EmailTo = "mail#mail.com";
$Subject = "New Webinar Registration";
// prepare email body text
$Body .= "Firstname: ";
$Body .= $firstname;
$Body .= "\n";
$Body .= "Lastname: ";
$Body .= $lastname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$headers = 'From: mail#mail.com' . "\r\n" .
'Reply-To: mail#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$conf_subject = "Registration Complete ...";
$conf_body = "Dear " . $firstname . ",\n\nThank you..." ;
$conf_body .= "Content-Type: text/calendar; name=\"".$file."\"\r\n" ;
$conf_body .= "Content-Transfer-Encoding: quoted-printable\r\n";
$conf_body .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
$conf_body.= $content."\r\n\r\n";
$conf_headers = 'From: web#mail.com' . "\r\n" .
'Reply-To: web#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
$conf_mail = mail($email, $conf_subject, $conf_body, $conf_headers);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
//Attached is an Outlook calendar invite so that you can plan your day accordingly.\n\n
?>
What should I do here? Is my encoding wrong?
You might have already seen this:
PHP Sending Mail
As a suggestion you might wanna have a look into PHPMailer which narrows down the work you have to do, to a single line of code:
$mail->addAttachment('/var/tmp/file.tar.gz');
After successful execution of command I want to send two different mails to two different person through if else function in PHP. I am able to send a mail using below code. How to send another mail with different headers & contents.
// if new reservation has been successfully added to reservation table
// send notification to admin via email
if($result){
$to = $email;
$subject = $reservation_subject;
$message .= $reservation_message."\r\n\n";
$message .= "Customer name:" .$provinsi."\r\n";
$message .= "Special Request :" .$comment."\r\n";
$from = $admin_email;
$headers = "From:" . $from."\r\n".
mail($to,$subject,$message,$headers);
echo "OK";
}else{
echo "Failed";
}
This is all you need to do, just set the new reciever and sender and message and call mail() again
Mail is much like any PHP function, you set up its parameters and call it.
if($result){
$to = $email;
$subject = $reservation_subject;
$message .= $reservation_message."\r\n\n";
$message .= "Customer name:" .$provinsi."\r\n";
$message .= "Special Request :" .$comment."\r\n";
$from = $admin_email;
$headers = "From:" . $from."\r\n".
if ( mail($to,$subject,$message,$headers) ) {
echo "OK message 1 sent";
} else {
echo "FAILED message 1 sent";
}
$to = $email_2;
$subject = $reservation_subject_2;
$message = $reservation_message_2."\r\n\n";
$from = $admin_email_2;
$headers = "From:" . $from."\r\n".
if ( mail($to,$subject,$message,$headers) ) {
echo "OK message 2 sent";
} else {
echo "FAILED message 2 sent";
}
}else{
echo "Failed";
}
Try This code :
function send_mail($to_email,$from_email,$subject,$message){
$nameToBeDisplayed = "XYZ";
$headers = 'From: ' . $nameToBeDisplayed . '<' . $from_email . '>' . "\r\n";
$headers .= 'Reply-To: ' . $from_email . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$message = "";
mail($to_email, $subject, $message, $headers);
}
if($result){
send_mail('to1#gmail.com','from1#gmail.com','your subject','your message');
send_mail('to2#gmail.com','from2#gmail.com','your subject','your message');
}else{
echo "Failed";
}
if($result){
createEmailOne();
createEmailTwo();
}else{
echo "Failed";
}
function createEmailOne(){
$to = $email;
$subject = $reservation_subject;
$message = $reservation_message."\r\n\n";
$message .= "Customer name:" .$provinsi."\r\n";
$message .= "Special Request :" .$comment."\r\n";
$from = $admin_email;
$headers = "From:" . $from."\r\n".
mail($to,$subject,$message,$headers);
echo "OK";
}
function createEmailTwo(){
$to = "john#snow.com";
$subject = $reservation_subject;
$message = "Something went wrong in this form, here is the info: \r\n\n";
$message .= $reservation_message."\r\n\n";
$message .= "Customer name:" .$provinsi."\r\n";
$message .= "Special Request :" .$comment."\r\n";
$from = $admin_email;
$headers = "From:" . $from."\r\n".
mail($to,$subject,$message,$headers);
echo "OK";
}
<?php
$to = 'maryjane#email.com';
$subject = 'Marriage Proposal';
$from = 'peterparker#email.com'; // 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"; // Create email headers
$headers .= 'From: '.$user_email."\r\n". 'Reply-To: '.$user_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); // Compose a simple HTML email message
$message = '<html><body>'; $message .= '<h3 style="color:#f40;">Email:<?php echo $from;?></h3>'; $message .= '<h3>Phone:<?php $phone;></h3>'; $message .= '</body></html>'; // Sending email
if(mail($to, $subject, $message, $headers))
{
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
$message = '<html><body>';
$message .= '<h3 style="color:#f40;">Email:'.$from.'</h3>';
$message .= '<h3>Phone:'.$phone.'</h3>';
$message .= '</body></html>'; // Sending email
If Its a PHP script, then you can use any PHP function including echo.
Clean way to do this -
echo '<h3>'.$phone.'</h3>';
I am having problems with this contact page, emails are being sent fine but are blank! I cant seem to find a solution. I would of thought $_POST would need to be added, however, the web hosting companies says it is not necessary in this php script Thankyou for your time and help. Code snippet below.
<?php
$EmailFrom = "sales#ibdengland.co.uk";
$EmailTo = "kent.collins.uk#gmail.com";
$Subject = "online form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Description of project']));
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("Location: http://www.ibdengland.co.uk/thankyou.html");
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 .= "Description of project: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
?>
You forgot to add the headers.
Example:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '. $EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Try changing:
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
To:
$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");
you have not use any header.
take help from here. and use it. I think it will help you.
post header like below
$headers = 'From:'.$EmailFrom . "\r\n" .
'Reply-To: '.$EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
then replace below
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
with the below code
$success = mail($EmailTo, $Subject, $Body, $headers);
plz try this one. and inform me if this work or not.
I have an html form the links to a PHP email. The form works well, but I am having trouble with the Cc and Bcc not coming through.
Here is the entire code. Please review and help me understand what I am getting wrong on the Cc and Bcc parts in the headers.
Thanks:
<?php
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
$email9_11 = $_POST['9-10'];
$email10_11 = $_POST['10-11'];
$email11_12 = $_POST['11-12'];
$email12_1 = $_POST['12-1'];
if (empty($emailFromName)) {
echo 'Please enter your name.';
} elseif (!preg_match('/^([A-Z0-9\.\-_]+)#([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} else {
$emailTo = "main#gmail.com" ;
$subject = "Family History Conference Registration";
if (!empty($emailFrom)) {
$headers = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$headers = 'From: Family History Conference <noreply#domain.org>' . "\r\n";
$headers .= 'Cc: $emailFrom' . "\r\n";
$headers .= 'Bcc: myemail#domain.com' . "\r\n";
}
$body = "From: ".$emailFromName."\n";
$body .= "Email: ".$emailFrom."\n";
$body .= "Phone: ".$emailFromPhone."\n\n";
$body .= "I would like to attend the following classes.\n";
$body .= "9:10 to 10:00: ".$email9_11."\n";
$body .= "10:10 to 11:00: ".$email10_11."\n";
$body .= "11:10 to 12:00: ".$email11_12."\n";
$body .= "12:10 to 1:00: ".$email12_1."\n";
/* Send Email */
if (mail($emailTo, $subject, $body, $headers)) {
echo "<h2>Thank you for Registering</h2>
<h3>You have registered for the following classes</h3>
<p>9:10 to 10:00am: \"$email9_11\" <br />
10:10 to 11:00am: \"$email10_11\"<br />
11:10 to 12:00: \"$email11_12\"<br />
12:10 to 1:00: \"$email12_1\"</p>
<p>We look forward to seeing you October 31, 2010</p>";
} else {
echo 'There was an internal error while sending your email.<br>';
echo 'Please try again later.';
}
}
?>
You're using single quotes
$headers .= 'Cc: $emailFrom' . "\r\n";
PHP won't interpret variables inside single quotes, you must use double quotes
$headers .= "Cc: $emailFrom\r\n";