How to add a cc in a php contact form? - php

I have a contact form for a HTML page. Right now the recipient is only one. How can I add multiple recipient. Any help on this would be a great help.
Code is below.
Thanks.
<?php
$to = "support#domain.in";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = "Message from $name ($email)";
$replyto = $email;
$headers="";
$headers = "From: test <domain#one.com>\n";
$headers .= "Reply-To: $replyto";
$result = mail($to,$subject,$message,$headers);
?>

Here is your sample code
$to = "xyz#somedomain.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc#somedomain.com \r\n";
$header .= "Cc:afgh#somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}

Related

How to Attach some Files In Mail in Simple PHP

I have made mail function in PHP, I use mail_to function and simple mail has been sent but the attachment file didn't. in this code I want the user send any type of file in the mail If I use any code of attachment get the error in page and page not open anyone helps me?
if(isset($_POST['submit']))
{
$pack = $_POST['pack'];
$position = $_POST['position'];
$name = $_POST['name'];
$email = $_POST['email'];
$re_no = $_POST['re_no'];
$phone = $_POST['phone'];
$rfc_no = $_POST['rfc_no'];
$comment1 = $_POST['comment1'];
$comment2 = $_POST['comment2'];
$comment3 = $_POST['comment3'];
$tandc = $_POST['tandc'];
$tandc2 = $_POST['tandc2'];
$file1 = $_POST['file1'];
$file2 = $_POST['file2'];
$file3 = $_POST['file3'];
$to = 'bhupendra.w3ondemand#gmail.com';
$subject = 'MUV Express Delivery Enqury';
$headers = "From: $email";
$message = "Package: $tp\r\n";
$message = "Package2: $pack\r\n";
$message = "Name: $name\r\n";
$message .= "Email: $email \r\n";
$message .= "Phone: $phone \r\n";
$message .= "Re No: $re_no \r\n";
$message .= "Position: $position \r\n";
$message .= "R.F.C. No.: $rfc_no \r\n";
$message .= "Comment1: $comment1 \r\n";
$message .= "comment2: $comment2 \r\n";
$message .= "comment3: $comment3 \r\n";
$message .= "Check: $tandc \r\n";
$message .= "Check2: $tandc2 \r\n";
$message .= "File1: $file1 \r\n";
$message .= "File2: $file2 \r\n";
$message .= "File3: $file3 \r\n";
$message .= "Brief Description: $briefdesc \r\n";
$sent = mail($to, $subject, $message, $headers);
$_SESSION["po"] = $_POST['position'];
if($sent) {
echo "Success";
header("Location: http://dev.w3ondemand.com/development/muvexpress/profile.php");
}
else {
echo "Failure";
header("Location: http://dev.w3ondemand.com/development/muvexpress/negocios.php");
}
}
Please map your variables accordingly.
<?php
$subject = 'Your message subject';
$encoded_content = chunk_split(base64_encode($your_file_content_here));
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$your_from_email."\r\n";
$headers .= "Reply-To: ".$reply_to_email."\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
//plain text
$message .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n\r\n";
//attachment
$message .="Content-Type: $file_type; name=".$file_name."\r\n";
$message .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$message .="Content-Transfer-Encoding: base64\r\n";
$message .="X-Attachment-Id: ".rand(1000, 99999)."\r\n\r\n";
$message .= $encoded_content;
$sentMailResult = mail($to, $subject, $message, $headers);
?>

Php contact form keeps going to spam and has an html attachement

I experiencing a problem with a php contact form that I normal use on our products sites.
<?php
$to = "martin#puritech.co.za";
$subject = "Reverse Osmosis";
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['tel'];
$mail = $_POST['message'];
$headers = "From: $name \r\n";
$headers .= "Email: $email \r\n";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html charset=iso-8859-1 \r\n";
$message = "<html><body style='font-family: Arial;'>";
$message .= "<h1>Hello Guys! You have a request from ".$name."</h1>";
$message .= "<p>".$mail."</p>";
$message .= "<p><span style='font-weight:bold;'>From:</span> ".$name."</p>";
$message .= "<span style='font-weight:bold;'>Email:</span> ".$email."</p>";
$message .= "<span style='font-weight:bold;'>Contact Number:</span> ".$number."</p>";
$message .= "</body></html>";
$send = mail ($to, $subject, $message, $headers);
if ($send==true) {
header('Location: ../index.html');
exit;
}else {?>
<script type="text/javascript">
alert('Please check your details and resend. Thank you.');
window.location = '../index.html';
</script>
<?php
}
?>
When I click on the send button, the mail goes straight to spam and has an html doc attachment.
How do I fix this? really draining me and its starting to annoy me.

Mail is not Going in PHP

i am not able to send email in php,Any one help me to identify
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem. where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
<?php
$englishname = $_REQUEST['firstname'].'&nbsp'.$_REQUEST['lastname'];
$arabicname = $_REQUEST['firstnamearabic'].'&nbsp'.$_REQUEST['lastnamearabic'];
$education = $_POST['education'];
$ar_education = $_POST['educationarabic'];
$email = $_POST['email'];
$country= $_POST['parent_cat'];
$city= $_POST['cit_cat'];
$area= $_POST['area'];
$mobilenumber= $_POST['mobileno'];
$doorno= $_POST['doorno'];
$phone= $_POST['phoneno'];
$street= $_POST['street'];
$apartment = $_POST['apartment'];
$experience = $_POST['experience'];
$postalcode = $_POST['postelcode'];
$landmark = $_POST['landmark'];
if(isset($_POST['requesttype'])&&$_POST['requesttype'] == 'addEmployee')
{
$to = 'arundsti#gmail.com';
$subject = 'NEW DOCTOR REGISTRATION DETAILS-FIND A DOCTOR';
$from = $_REQUEST['email'];
// mandatory headers for email message, change if you need something different in your setting.
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "CC: info#findadoctorsa.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "Name in English: $englishname.\r\n";
$message .= "Name in Arabic: $arabicname.\r\n";
$message .= "Education: $education \r\n";
$message .= "Education in Arabic: $ar_education \r\n";
$message .= "Email: $email \r\n";
$message .= "Country: $country \r\n";
$message .= "City: $city \r\n";
$message .= "Area: $area \r\n";
$message .= "Mobilenumber: $mobilenumber \r\n";
$message .= "DoorNumber: $doorno \r\n";
$message .= "PhoneNumber: $phone \r\n";
$message .= "Street: $street \r\n";
$message .= "Apartment: $apartment \r\n";
$message .= "Experience: $experience \r\n";
$message .= "Postalcode: $postalcode \r\n";
$message .= "Landmark: $landmark \r\n";
$sent = mail($to, $subject, $message, $headers);
if($sent){ ?>
<script>
alert('Your Details received Successfully...We will Touch with you shortly');
</script>
<?php
}
else {?>
<script>
alert('Sorry Problem in Submitting Details,Please try Again');
</script>
<?php
}
}
?>

Send BCC in PHP

Need to send a BCC copy to a user2#gmail.com
Not familiar with PHP and I'm missing something.
<?php
if(empty($_POST['name2']) || empty($_POST['email2']) || empty($_POST['message2']))
{
return false;
}
$name2 = $_POST['name2'];
$email2 = $_POST['email2'];
$message2 = $_POST['message2'];
$to = 'user1#gmail.com'; // Email submissions are sent to this email
// Create email
$email_subject = "Message from Website;
$email_body = "You have received a new message. \n\n".
"Name2: $name2 \nEmail2: $email2 \nMessage2: $message2 \n";
$headers = "From: user1#gmail.com\n";
$headers .= "Reply-To: $email2";
$headers .= "Bcc: user2#gmail.com" . "\r\n";
mail($to,$email_subject,$email_body,$headers); // Post message
return true;
?>
at the end of any $header line fix that end with "\r\n"
$headers = "From: user1#gmail.com\r\n";
$headers .= "Reply-To: $email2\r\n";
$headers .= "Bcc: user2#gmail.com\r\n";
try now

PHP mail function ignoring additional headers

I'm trying to send a mail using the php mail() function
but for some reason I don't get, additional headers are ignored.
This is my code:
$errors = '';
$myemail = 'my#email.com';
$myemail_bcc = 'my_bbc#email.com';
if(empty($_POST['nome']) || empty($_POST['email']))
{
$errors .= "Error: You must fill Name and Email fields";
}
$name = $_POST['nome'];
$email_address = $_POST['email'];
$telefono = $_POST['telefono'];
$message = $_POST['messaggio'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br />Error: You must use a valid email address";
}
// spediamo la mail
if( empty($errors))
{
$to = $myemail;
$email_subject = "New Request from: $name";
$email_body = "User data:.\n\n";
$email_body .= "Nome: $name \nEmail: $email_address \nTelefono: $telefono \n";
$email_body .= "Messaggio: \n$message";
$headers = "From: John Smith <$myemail>\r\n";
$headers .= "Reply-To: $name <$email_address>\r\n";
$headers .= "Bcc: $myemail_bcc";
mail($to,$email_subject,$email_body,$headers);
}
I've tried to vary the way I declare headers without names, just with emails:
$headers = "From: $myemail \r\n";
$headers .= "Reply-To: $email_address\r\n";
$headers .= "Bcc: $myemail_bcc";
and even just on one line
$headers = "From: $myemail\r\nReply-To: $name <$email_address>\r\nBcc: $myemail_bcc";
But in no case the mail is sento to the Bcc address, and the "reply" function in client email does not use the Reply-to address.
where am I wrong?

Categories