Send email using php emailing to multiple people - php

I have a php email script here but it will only take one email. How can i set this up to take multiple emails say upto 500? if i were to enter them as such.... email1#aol.com, email2#aol.com, email3#aol.com ect sperated by commas?
From Address: <input type="text" id="from" value="fakeemailer#albertyw.mit.edu" size="40"><br>
Recipient Address: <input type="text" id="to" size="40"><br>
Subject: <input type="text" id="subject" size="40"><br>
Message: <br><textarea id="message" cols="50" rows="10"></textarea><br>
<input type="submit" onclick="javascript:sendmail()" value="SEND">
$headers = $_POST['headers'];
$from = $_POST['from'];
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers .="From: $from";
mail($to, $subject, $message, $headers) or die("EMAIL FAIL");
echo $to."<br-->";
echo $subject."<br>";
echo $message."<br>";
echo $headers."<br>";
echo 'EMAIL SENT';

Exactly as you put it in your question. Commas separate multiple recipients.
Mail() in the PHP manual is a good place to start.

try this
<input type="text" id="to" value="fakeemailer#albertyw.mit.edu, email2, email3, email4" name="to">

Related

Problems with PHP contact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a problem with my contact form that I have created. When the user clicks on the send email button, I receive the email with a header, but I can't see the user's input.
So basically I am able to see the header($subject) and the pre written text("This is an automated message"), but I am not able to see the contents of $email and $message. What could be wrong?
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
you need to check whether you have post parameters then send the email
change your code to
<?php
if(isset($_POST['email']) && isset($_POST['message'])){
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
Try like this
<?php
$email = $_POST['email'];
$message = $_POST['message'];
$to = "test#testemail.com";
$subject = "New Message!"; $body = "This is an automated message. Please do not reply to this email. \n\n $email \n\n $message";
$body= $_POST["message"]
if ($_SERVER["REQUEST_METHOD"] == "POST") {
mail($to, $subject, $body); echo "Message Sent.";
}
?>
<form id="contact-me-form" action="contact.php" name="contact_form "method="post">
<input type="text" name="email" placeholder="Email Address">
<textarea name="message" placeholder="Type Your Message Here"></textarea>
<input id="sendEmail" type="submit" name="submit" value="Send">
</form>
This will send an email to test#testemail.com when the user submit a message in the form

PHP contact form

I've looked through a lot of pages to find an answer for my problem. But I can't figure out why my form isn't working.
I tried different versions of codes from premade examples but I can't get it to work.
This is my php above my form
<?php
$name = $_POST['name'];
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'me#email.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
?>
and this is my form
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" placeholder="Your Name">
<label>Email</label>
<input name="email" type="email" placeholder="Your Email">
<label>Subject</label>
<input name="subject" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
I've only changed my email in this example here the rest is the same. I'm testing this live on a modern server with php 5+ support
Basicly everything works fine except that I don't get an email.
I can't find out how to make it work sadly. Any ideas would be cool :/
Edit: GOD DAMNIT IM A TOTAL IDIOT
Gmail Spam filter is strong in this one.
You have not defined $from.
That is why it is not sending mail.
Also, please check SMTP settings for your machine/server.
SMTP ports may not be configured, that is why mail is not sending.
Try this for the form:
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" type="text" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
Also try following this working format:
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
?>
You could just replace the value inside the " " with the post function.
Edit ( This will surely work ):
if (isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
The fourth Parameter for the Mail function is header. Where You can set Mail form and others (http://php.net/manual/en/function.mail.php ). Please set that, and also check the SMTP configuration as "Programming Student" told you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'to#test.com';
$from = 'from#test.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again! </p>';
}
?>
You have missed to assign the $from variable
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"> </textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
Make sure the php file name "contact.php"
Now My HTML goes this way -->
<body> Fields with * are mandatory.
<form action="mail.php" method="POST">
<fieldset>
<legend>Contact Information</legend>
<p>Name*</p> <input type="text" name="name">
<p>Email*</p> <input type="text" name="email">
</fieldset>
<br />
<br />
<fieldset>
<legend>Other Information</legend>
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Contact Us</option>
<option value="change">Information Change</option>
<option value="addition">Other</option>
</select>
<br />
</fieldset>
<br />
<fieldset>
<legend>Your Message</legend>
<p>Message*</p><textarea name="message" rows="8" cols="29"></textarea><br /><p>
<input type="submit" value="Send" class="but"> <input type="reset" value="Clear" class="but">
</fieldset>
</form>
</body>
and now the main thing that is PHP goes this way ->
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "youremail#domain.com";
$subject = "Contact Form";
$mailheader = "$name submited the form.";
if (filter_var("$email", FILTER_VALIDATE_EMAIL)) {
if ($email === "" || $message === "" || $name === "") {
echo "ERROR! Email and message and Name are Mandatory. <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
else {
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, "Name of Form Here", "Your Form has been submitted. Your problem will be noticed soon. This is a no reply mail address. Please dont reply back. - WeBoosters India", "Thankyou") or die("Error!");
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
}
else {
echo "The email is not valid. Please write a proper email address. - <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
?>
Hope you like it! Best of luck.

Unable to receive form info mail

I am attempting to send the details in the fields of a contact form to my mail id. I dont seem to be getting any errors when I hit
submit but I am not receiving any mail.
Here is my code
<?PHP
$email = $_POST["email"];
$to = "myemail#example.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following details to you.\n
Name : $name
Email Address: $email
Phone number: $phone
Message: $message";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: myemail#example.com\n";
$usermessage = "Thank you for contacting us.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
<form id="contact-form" class="contact-form" action="contact-form-info.php" enctype="text/plain" >
<div id="result" class="result"></div>
<input type="text" name="name" id="name" placeholder="Name *">
<input type="text" name="email" id="email" placeholder="E-mail *">
<input type="text" name="phone" id="phone" placeholder="Phone *" onChange="PhoneValidation(this)" ;>
<textarea cols="5" rows="5" name="message" id="message" placeholder="Message *"></textarea>
<input type="submit" class="btn-dark" value="SEND">
Your form is:
Encoding the data as text/plain, which isn't machine readable
Sending the data as GET not POST (which is what you are trying to read)
Remove the enctype attribute and add method="POST"
You are also never assigning values to $name or $phone.

How can I send an email to an email address provided in a hidden input field?

I've got a simple PHP email form. This is going to be used for multiple people, so in order to make it easier for people, I have a hidden input field in my html form that is basically the "mailTo" email address.
How do I get the email to send the email to the address provided in the hidden input field?
Here's my HTML:
<div id="formholder">
<form method="post" action="http://www.artofliz.com/hosting/php/process.php">
<!-- THE CLIENT'S EMAIL TO ADDRESS GOES HERE!!! -->
<input name="to" type="hidden" value="lroberts#platinumstrategies.com" />
<label for="name">Name</label>
<input name="name" placeholder="Full Name" type="text" />
<label for="email">Email</label>
<input name="email" placeholder="youremail#example.com" type="email" />
<label for="phone">Phone</label>
<input name="phone" placeholder="XXX-XXX-XXXX" type="tel" />
<input id="submit" name="submit" type="submit" value="Submit" />
</form>
</div>
Here is my PHP handler:
<?php
$to = $_POST['to'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$from = 'From: noreply#platinumstrategies.com';
// $to = 'lroberts#platinumstrategies.com';
$subject = 'Free Guide Download';
$body = "From: $name\n Email: $email\n Phone: $phone";
if ($_POST['submit']) {
/* Anything that goes in here is only performed if the form is submitted */
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
http://pastebin.com/cqZP949r - Additionally, I should note that the 'to' that's commented out works fine. It's what I'm trying to do currently that's broken.
Thank you very much for your help.

PHP Mail HTML Comment Form Variables

Can you provide the proper syntax to pass the html form variables to php mailer?
The php is:
$comment = $_POST['comment'];
$email = $_POST['email'];
$to = 'sssff#gmail.com';
$subject = 'From Website';
$message = $comment;
$headers = 'From: $email';
mail($to, $subject, $message, $headers);
$message needs to contain the contents of $comment
$headers needs to display the contents of $email as return address
Can anyone help me with the proper syntax? Thank you
EDIT
To clarify, the email i receive from the php mailer does not contain the from address contained by $email, nor does the message contain the comments from $comment.
The email is sent fine, but does not contain those crucial elements.
If you'd like to look at the form it is:
<form class="cmxform" id="commentForm" method="POST" action="">
<label for="cname">Name</label>
<input id="cname" type="text" name="name" size="60" class="required" minlength="2" />
<label for="cemail">E-Mail</label>
<input id="cemail" type="text" name="email" size="60" class="required email" />
<label for="curl">URL</label>
<input id="curl" type="text" name="url" size="60" class="url" value="" />
<label for="ccomment">Your comment</label>
<textarea id="ccomment" type="text" name="comment" cols="72" rows="8" class="required"></textarea>
<div id="button2"><input class="submit" id="submit_btn" type="submit" value="Send Email"/></div>
</form>
Thank you for your help
$headers = 'From: $email';
^--- ^---
should be " instead. Single quoted strings do not interpolate variables, so you're using a literal $email as your From address, not someone#example.com.
$comment = $_POST['comment'];
$email = $_POST['email'];
$to = "$email";
$from = 'sender email';
$subject = 'message subject';
//Begin HTML Email Message
$message = "$comment";
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
mail($to, $subject, $message, $headers);

Categories