I have a php file which sends an email after a contact form has been submitted.
The email delivers correctly to the recipient, but it does never deliver to the Cc and Bcc. In the received email, anyways, the Cc is there(of course Bcc doesnt show up but if Cc is there Bcc should be too), but it just does not deliver to them.
Here is the code
<?php
$from = 'xx#xxx.com';
$to = $_POST['mail'];
$name = $_POST['nombre'];
$lastname = $_POST['apellido'];
$msg = "this is the content of the mail";
$subject = 'this is the subj';
$headers = "From:".$from."\r\n";
$headers .= "Cc:".$from.", xxx#xxx.com,xxy#xxy.com\r\n";
$headers .= "BCC:xyx#xyx.com\r\n";
if ($name=="" || $lastname=="" || $_POST['mensaje']=="" || $to==""){
echo '0';
}else{
if(mail($to, $subject, $msg, $headers)){
echo '1';
}else{
echo '-1';
}
}
?>
Related
i have a string like:
$email = 'xyz#email.com,abc#email.Com,and others#email.com';
AND
$msg = 'SEND these to each email above thanks';
in my achievement i want to be able to send text in the $msg as an email message to each email in $email example:
$to = 'xyz#email.com';
$msg = 'SEND these to each email above thanks';
$to = 'abc#email.com';
$msg = 'SEND these to each email above thanks';
$to = 'others#email.com';
$msg = 'SEND these to each email above thanks';
foreach($email as $email)
{
$to = $email["to"];
$subject = 'the subject';
$message = '$msg';
$headers = 'is this really? ';
mail($to, $subject, $message, $headers);
}
big thanks for your impact in my soluction
Try splitting the emails string and for each email execute the code that sends the mail
<?php
$emails = 'email1#example.com,email2#example.com';
$emailsSplitted = explode(',', $emails);
foreach ($emailsSplitted as $email) {
// ...
// use here the variable $email to send the message
}
I have contact form. I'd like to add CC to e-mail: abc#abc.de and change e-mail sender. Currently it shows my server as a sender, I'd like to have reply-to form users.
Hello.
I have contact form. I'd like to add CC to e-mail: abc#abc.de and change e-mail sender. Currently it shows my server as a sender, I'd like to have reply-to form users.
<?php
session_start();
//Ajax Questions Form
if(isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$arrival = $_POST['arrival'];
$departure = $_POST['departure'];
/// $adults = $_POST['adults'];
// $children = $_POST['children'];
// $room = $_POST['room'];
$requests = $_POST['requests'];
$to = 'contact#test.camp'; //Replace with recipient email address
$subject = 'Hotel Booking'; //Subject line for emails
$message = 'From: '.$name."\r\n".'Email: '.$email."\r\n".'Arrival: '.$arrival."\r\n".'People: '.$departure; //."\r\n".'Adults: '.$adults."\r\n".'Children: '.$children."\r\n".'Room: '.$room."\r\n".'Requests: '.$requests;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
echo "Your email was sent!"; // success message
}
}
//Contact Php Form
if(isset($_POST['contact_email'])){
$contact_name = $_POST['contact_name'];
$email = $_POST['contact_email'];
$contact_message = $_POST['message'];
$to = 'marek#gmail.com'; //Replace with recipient email address
$subject = 'Contact Form'; //Subject line for emails
$message = 'From: '.$contact_name."\r\n".'Email: '.$email."\r\n".'Message: '.$contact_message;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // This line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
}
}
?>
The php mail function does not have much functionality try using something like PHPMailer which allows you to send more complex emails
For add CC or BCC or ReplyTo add header to your email structure :
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'To: andreas<mail1#gmail.com>, thomas<mail2#gmail.com>';
$headers[] = 'From: from <from#gmail.com>\r\nReply-to: <ReplyTo#gmail.com>';
$headers[] = 'Cc: Cc#gmail.com';
$headers[] = 'Bcc: Bcc#gmail.com';
mail($to, $subject, $message, implode("\r\n", $headers));
I have a php file that needs to send an email to me if the contact section of my contact page has been filled in. And a checkbox whether to send a copy of the message or not. But for some reason if the checkbox is checked, the sender/maker of the message is not receiving a copy of this message in his mailbox.
See code below.
Kind regards
PHP file being called
<?php
//////////////////////////
//Specify default values//
//////////////////////////
//Your E-mail
$your_email = 'info#sano-tech.be';
//Default Subject if 'subject' field not specified
$default_subject = 'Van contact formulier';
//Message if 'name' field not specified
$name_not_specified = 'Geef een correcte naam in';
//Message if 'message' field not specified
$message_not_specified = 'Geeft een correcte boodschap in';
//Message if e-mail sent successfully
$email_was_sent = 'Versturen geslaagd!';
//Message if e-mail not sent (server not configured)
$server_not_configured = 'Sorry, mail server niet geconfigeerd';
///////////////////////////
//Contact Form Processing//
///////////////////////////
$errors = array();
if(isset($_POST['message']) and isset($_POST['username'])) {
if(!empty($_POST['username']))
$sender_name = stripslashes(strip_tags(trim($_POST['username'])));
if(!empty($_POST['message']))
$message = stripslashes(strip_tags(trim($_POST['message'])));
if(!empty($_POST['email']))
$sender_email = stripslashes(strip_tags(trim($_POST['email'])));
if(!empty($_POST['subject']))
$subject = stripslashes(strip_tags(trim($_POST['subject'])));
if(!empty($_POST['nummer']))
$nummer = stripslashes(strip_tags(trim($_POST['nummer'])));
$sendcopy = $_POST['sendcopy'];
//Message if no sender name was specified
if(empty($sender_name)) {
$errors[] = $name_not_specified;
}
//Message if no message was specified
if(empty($message)) {
$errors[] = $message_not_specified;
}
$from = (!empty($sender_email)) ? 'From: '.$sender_email : '';
$subject = (!empty($subject)) ? $subject : $default_subject;
//$message = (!empty($message)) ? wordwrap($message, 70) : '';
$message = "
Onderwerp: $subject
Naam: $sender_name
E-mail: $sender_email
Nummer: $nummer
Boodschap:
$message
";
//sending message if no errors
if(empty($errors)) {
if($sendcopy == "yes")
{
if (mail($your_email, $subject, $message, $from) && mail($sender_email, $subject, $message, $from)) {
echo $email_was_sent;
} else {
$errors[] = $server_not_configured;
echo implode('<br>', $errors );
}
}
else{
if (mail($your_email, $subject, $message, $from)) {
echo $email_was_sent;
} else {
$errors[] = $server_not_configured;
echo implode('<br>', $errors );
}
}
} else {
echo implode('<br>', $errors );
}
} else {
// if "name" or "message" vars not send ('name' attribute of contact form input fields was changed)
echo '"naam" en "bericht" variabelen zijn niet ontvangen door de server. Gelieve attributen hun "naam" te controleren';
}
?>
HTML (checkbox)
<div class="sc_contact_form_item sc_contact_form_checkbox">
<input type="checkbox" name="sendcopy" value="yes" id="contact_form_checkbox" checked> Stuur mij een kopie van het bericht
</div>
What I did until now:
1) add a new mail account: no-reply#domain.be
2) added $headers with 'Reply-To:', 'From:' and 'X-Mailer:'
It's working now and showing the correct addresses in the mail.
But if the check is made to send a copy the mail still ends up in spam folder. How can I solve this?
Mail Fucntion Syntax:
mail(to,subject,message,headers,parameters);
How add BCC
Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).
Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file.
Example
$to = "name#mydomain.com";
$subject .= "".$emailSubject."";
$headers .= "Bcc: ".$emailList."\r\n";
$headers .= "From: no-reply#thepartyfinder.co.uk\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= 'THE MESSAGE FROM THE FORM';
if (mail($to, $subject, $message, $headers)) {
$sent = "Your email was sent!";
} else {
$sent = ("Error sending email.");
}
Why Is My Email Going to The Spam Folder?
Don’t use your email address for the “from” email address.
If you send a email that is “from” your email (let’s say test#activecampaign.com) and you send it to a contact with the email (test#activecampaign.com) it will most certainly be marked as spam as the “from” and the “to” is the same.
Pay attention to the spam filter testing before sending.
Don’t send a single graphic/image
Don’t use a free email address as your “from” email
Test different subjects & email contents
Pay attention to your links in your email
Don’t include links that use link shortening services
Take the time to code your HTML correctly
Remove inactive contacts
Send using a consistent “from” email address
Never include Javascript, form code, or video within your email
Avoid copying anything directly from Microsoft Word, Excel,
Powerpoint, etc..
I have the below PHP contact form that has a CAPTCHA code to ensure is correct. However, when I reply to the email from the website it puts a random email which i believe is the server admin, however, I want it to be the persons email who sent the form in. below is the code, could you possibly be able to help me?
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty ($_SESSION['chapcha_code'] ) ) {
$youremail = 'info#example.com';
$fromsubject = 'www.example.co.uk';
$title = $_POST['title'];
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = $youremail;
$mailsubject = 'Message from Website'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is: '.$fname.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for your message. I will contact you shortly if needed.<br/>Go to <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please go to <a href='/contact.html'>Contact Page</a>";
}
?>
You'll need some headers so the from address is the users mail.
Also refer to the mail docs
try this
$headers = "From: $mail\r\n";
$headers .= "Reply-To: $mail\r\n";
mail($to, $subject,$body,$headers);
I'm creating a 'forgot password' page where the user enters their email address and the script finds the password associated to that email, and sends it to the stored email address.
I believe the problem has to do with my SMTP Mailserver. I am using WAMP which doesn't have one so I downloaded one that was free.
This is the php script I'm using:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = #mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
The $msg outputs properly so I know the code is passing the mail function.
Try sending in a proper "From" in $header.
$emailFrom = "admin#yourdomain.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
See details of the mail() function.
If this doesn't work, try using PHPMailer. You configure it in code, no need to edit php.ini.
I've used it in some projects (v 2.0.4, I see the latest is 5.1) and had no problems.
Try using Google's server to send mails, you can see how to do that here
Try using this
//Email information
$to = "garggarima#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support#sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";