PHP email not sending to multiple recipients [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Sending mail to multiple recipients
(3 answers)
Closed 4 years ago.
After submitting a PHP form, I want an email to go to multiple recipients, but it does not. It goes to only the first address. It says in the email (in the "To" field that it is sending to the 3 addresses, but it is not. How can I add a CC or BCC to this code (if that is what is needed)? There are question about this on here and I've tried everything I've seen, but nothing is working so far. Thanks in advance.
Here is my code:
$headers = 'From: CBS Website';
$emailbody = 'Name: '.$_POST['name']."\n"
.'Company: '.$_POST['company']."\n"
.'Email: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Stage: '.$_POST['stage']."\n"
.'Budget Range: '.$_POST['budget']."\n"
.'Geographic Location: '.$_POST['location']."\n"
.'Permanent: '.$_POST['permanent']."\n"
.'Semi-permanent: '.$_POST['semi-permanent']."\n"
.'Special Considerations: '.$_POST['considerations']."\n"
.'Project Type: '.$_POST['projectType']."\n"
.'Square Footage: '.$_POST['sqfootage']."\n"
.'Number of Stories: '.$_POST['stories']."\n"
.'Schedule: '.$_POST['schedule']."\n"
.'SF Budget: '.$_POST['sfbudget']."\n"
.'Future Construction: '.$_POST['futureConst']."\n"
.'Special Features: '.$_POST['features']."\n"
.'Restrictions: '.$_POST['restrictions']."\n"
.'Referral: '.$_POST['referral']."\n";
mail("joedoe#domain.com,janedoe#domain.com,jimmy80#domain.com",'Contact Form Submission', $emailbody, $headers);
echo "<meta http-equiv='refresh' content=\"0; url=thankyou.php\">";

Related

how can i redirect back to previous page after message sent from form [duplicate]

This question already has answers here:
Redirecting to previous page after login?
(18 answers)
Closed 2 years ago.
hi how can i send back to previous page in php
<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. persons number is: ".$_POST['phone']." message is: ".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
?>
Try using php header function.
Example would be in PHP
header("Location: $_SERVER['HTTP_REFERER']");
Where $_SERVER['HTTP_REFERER'] by PHP.net is
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from.
persons number is: ".$_POST['phone']." message is:
".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
// Redirect after mail
header("Location: $_SERVER['HTTP_REFERER']");
?>
Use can use this for redirections -
header("Location: pagename.php");
Replace pagename.php with your page.
Place it below mailing code so that it will redirect after the mail gets sent.

how can i style a sending email with inline css [duplicate]

This question already has answers here:
Php mail: how to send html?
(5 answers)
Closed 5 years ago.
I 'm using a single form to allow my guests subscribe on my upcoming website.
My problem is that i really dont know how to make this email has some css style. I tried inline css but nothing happens. The email i receive just display the code of styling and it doesnt transform it into html!
The code i use is this:
<?php
if(isset($_REQUEST["isvalid"])){
$youremail = "info#mywebsite.com;
$usersemail = $_POST["usersemail"];
$mailsubject = "You have a new subscriber";
$message ="
<div style='width:300px;padding:20px;margin:0 auto;background:#84C318;color:#ffffff;border-radius:3px;'>
Email Address: $usersemail
</div>
";
$headers = 'From:' . $usersemail . "\r\n";
mail($youremail, $mailsubject, $message, $headers);
echo "success";
} else {
echo "failed";
}
?>
I am not sure but i think i can add inline css style inside a variable. i also tried to move the inline style outside the variable but i got the same result.
Need some help here..
You need to specify that your email is a html email by setting the Content-type header to "text/html".
More information here: https://css-tricks.com/sending-nice-html-email-with-php/

Mail function not sending email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I'm pretty new to PHP and getting to grips with a (very simple) contact form. When I uploaded this to my hosting company, the PHP script does run as when I fill out and submit the form it brings back my confirmation but the email does not send. My hosting company is 123-reg. Do I have to do anything with them to allow the email to be sent?
My code is as follows:
Form Code:
<form action="action_handler.php" method="POST">
<dl>
<dt> Name:
<dd><input type="text" name="name">
<dt> Email Address:
<dd><input type="text" name="mail">
<dt> Comments:
<dd><textarea rows="5" cols "20" name="comment">
</textarea>
</dl>
<p><input type="submit"></p>
</form>
PHP Code:
<?php
$name = $_POST['name'];
$mail = $_POST['mail'];
$comment = $_POST['comment'];
$to = "someone#hotmail.co.uk";
$subject = "Contact Form Request";
$body = "You have a new message from: /n Name: $name /n Email: $mail /n/nThe request is as follows: /n/n $comment";
mail ($to,$subject,$body);
echo"<p>Thanks for your comment $name ...</p>";
echo"<p><i>$comment</i></p>";
echo"<p>We will reply to $mail</p>";
?>
Any help is much appreciated.
There are a few things wrong with your present code.
Firstly, /n which should read as \n very important. It's a syntax error.
Then, there's the missing From: which not having that in mail headers, will most likely be rejected or sent to spam.
The "from" in mail will end up being an email address from "#yourserver.xxx"
To include a From: use the following:
$header = "From: ". $name . " <" . $mail . ">\r\n";
which will show up as the person's name in the "from", yet identified as a proper email address.
More often than none, mail is sent to spam whenever From: is omitted from headers.
Therefore
mail ($to,$subject,$body);
should be modified to
mail ($to,$subject,$body,$header);
including the line above, to be inserted underneath the $body variable.
For more information on mail/headers, visit:
http://php.net/manual/en/function.mail.php
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
You can also use a conditional statement to check if mail was indeed sent:
if(mail ($to,$subject,$body,$header)) {
echo "Sent.";
} else{
echo "Sorry, check your mail logs.";
}
Once mail goes out, it's out of your server's hands and into the receiver's end. There's nothing you can do "after the fact."

How to make form fields required? [duplicate]

This question already has answers here:
Making email field required in php [closed]
(4 answers)
Closed 8 years ago.
I have this existing code and I am wondering how to make the name and email field required?
<?php
if(isset($_POST['submit'])){
$to = "xxx#email.com"; // this is your Email address
$from = $_POST['gift_email']; // this is the sender's Email address
$first_name = $_POST['gift_name'];
$subject = "Free Gift Request";
$msg = "A free gift has been requested from the following:"."\n";
$msg .= "Name: ".$_POST["gift_name"]."\n";
$msg .= "E-Mail: ".$_POST["gift_email"];
$headers = "From:" . $from;
mail($to,$subject,$msg,$headers);
//echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header('Location:free_program_thankyou.php');
}
?>
For form
<input type="text" name="gift_email" required>
<input type="text" name="gift_name" required>
For Php
if(empty($_POST['gift_email']))
{
echo 'This field is required';
}else {
//Do what you want to do here
}
A two basic ways to do this:-
Within the php program check each required form field has been filled in send a new page with an error message back if it is not. Be sure to return the contents of any fields already filled in or your users will wish a plague of boils on your person.
Validate in javascript. Have a function triggered by the "onsubmit" condition which checks for all required forms fields are filled and highlights any that are not. see here
In practice a robust web site will do both. This seems like duplication however the javascript function is much more responsive and user friendly, BUT, the php server side validation cannot be gamed by turning JS off or spoofing responses.

Want to use href inside php variable [duplicate]

This question already has answers here:
How to send HTML/CSS emails?
(4 answers)
Closed 8 years ago.
I need to send a verification email, its working fine. But i don want to show the "link" in the email i just need to show some text like "click here to verify"
{
$verify_email="
Hello,
Thank you for signup.
For verify e-mail go to this http://".$site_url."/verify.php?user=%s&key=%s;
Or enter your verify code on verification page. Code is: %s
Thanks you.
";
}
This sends a email like the below
Hello,
Thank you for signup.
For verify e-mail go to this http://testsite.com/verify.php?user=username&key=de94569d40077060f5f5eb;
But i need this to be
Hello,
Thank you for signup.
For verify e-mail click here
Please help me
{
$verify_email="
Hello,
Thank you for signup.
For verify e-mail <a href='http://".$site_url."/verify.php?user=%s&key=%s> go to this </a>
Or enter your verify code on verification page. Code is: %s
Thanks you.
";
}
This is regular HTML markup. Use the anchor tag and enclose your URL in the href attribute.
Use this code
<?php
$to = 'your recipients';
$subject = 'Your subject';
$message = 'Your html code';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Try this
$verify_email='
Hello,
Thank you for signup.
For verify e-mail go to this Click here
Or enter your verify code on verification page. Code is: %s Thanks you.';

Categories