I am unable to send email address carried from email box in html form.
when i fill up the form email box with someone#yahoo.com the email is send to the mailbox
but when i fill the form email box with someon#gmail.com the email script works but the email doesn't come in the mailbox or the spam folder.
-----*This is the html code*-------
<input type="email" name="email" id="email" size="70" /></td>
-----*-------------
$email_from = "$mail";
$email_to = "someone#gmail.com";
$email_message ="test message";
$email_subject = "Registration form "; // email subject line
$headers .= 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From:'.$mail;
mail($email_to, $email_subject, $email_message, $headers);
Related
So I've completed a contact form made in PHP. After testing it sends emails, but in the email header it is not capturing the sender's name or email address. It shows up as sh-908129268#eu.hosting-webspace.io
Is there a way to correct that? I need to be able to respond to emails.
The inputs are as follows:
<form id="contact" action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<input class="input is-small" type="text" name="name" placeholder="Text input" value="<?= $name ?>" >
<p class="help is-danger"><?= $name_error ?></p>
<input class="input" type="email" name="email" placeholder="Email Address" value="<?= $email?>">
<p class="help is-danger"><?= $email_error?></p>
// back-end file
$sendTo = 'test#email.com';
$subject = 'Business Enquiry';
$headers = "";
$headers .= "Sent From: ".$name. "\r\n";
$headers .= "Reply To: ".$email. "\r\n";
$headers .= "Message: ".$message. "\r\n";
if (mail($sendTo, $subject, $message, $headers)) {
$success = "Thank you for your message, I will reply as soon as I can.";
$name = $email = $message = ''; // resets all fields
}
You cannot pick the names of the headers freely, you have to adhere to the standard (RFC 5322 Internet Message Format).
Your header "Sent From" should be just From, your header "Reply To" should be Reply-To and your header "Message" shouldn't be in the headers at all - you already pass the message as such into the mail function.
All fixed now, thanks. All I needed was to specify one header ,
$headers = "From: ".$email;
So it's just $subject and $headers
I've been having problems using php in my html form. While it will send, the $_POST variables are empty when I try to grab them in the php file. Any ideas on what I could be doing wrong?
My HTML code:
<form class="submitAMessage" name="Submit a Message" method="post" action="sendresults.php">
<div>
<h4>Submit a Message:</h4>
<label for="name">Name:<br><span class="required"></span></label>
<input type="text" id="name" name="name" placeholder="Your name" required="required" />
</div>
<div> <br>
<label for="email">Email Address:<br><span class="required"></span></label>
<input type="email" id="email" name="email" placeholder="your#email.com" required="required" />
</div>
<div> <br>
<label for="message">Message:<br><span class="required"></span></label>
<textarea id="message" name="message" placeholder="Write your message here." required></textarea>
</div>
<div>
<input type="submit" id="submit" name="submit" formmethod="POST" value="Submit" />
</div>
</form>
My php file:
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Results from Contact Form';
$emailfrom = 'noreply#website.com';
// Your email address. This is where the form information will be sent.
$emailadd = 'website#gmail.com';
// Where to redirect after form is processed.
$url = 'http://www.website.com/main.html';
// Makes all fields required. If set to '1' no field can not be empty.
// If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from Form:\n\n";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$line = '
';
mail($emailadd, $subject, $text.$name.$line.$email.$line.$message, 'From: '.$emailfrom.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
The only thing that sends in the email is:
Results from Form:
Any help is appreciated, thanks in advance!
You need to pass the headers into the mail function which is option.
Here is the functions all parameters
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
$to Receiver, or receivers of the mail.
$subject Subject of the email to be sent.
$message Message to be sent.
$additional_headers this is the optional headers which is used for the mail options
you can to set the following values in headers.
// header configuration for to send the HTML mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
$additional_parameters The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail
You should use the header in mail function. Add following code in in your code too.
$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";
mail($emailadd, $subject, $text.$name.$line.$email.$line.$message,$header, 'From: '.$emailfrom.'');
Good luck.
So I have an email form using PHP:
<form method="post" action="contactus.php" autocomplete="off">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" maxlength="60" required/>
<label for="email">Email:</label>
<input type="text" name="email" id="email" maxlength="120" required/>
<label for="message">Message:</label><br />
<textarea name="message" rows="20" cols="20" id="message" required></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
And the PHP to send to my email:
<?php
if($_POST["submit"]) {
// The message
$message=$_POST["message"];
$email=$_POST["email"];
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('myemail.com', 'Quick Pass', $message, $email);
}
?>
But the problem is only 'myemail.com' (which is my email address), 'Quick Pass' (the email subject) and $message (the email message). $email isn't being sent.
I have tried:
<?php
$to = "myemail.com";
$subject = "Quick Pass";
$message=$_POST["message"];
$email=$_POST["email"];
mail($to,$subject,$message,$email);
?>
With this I am receiving four emails (two with $message and two with $email).
The problem is I need all of this in one email. So the $message is sent along with $email somewhere in the email.
Any ideas? (hopefully using my form)
There is an example, direct from the php manual, which looks as follows:-
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
The fourth parameter is NOT simply an email address - it is a header:value type arrangement with multiple headers separated using \r\n
In your code perhaps you could try:-
if($_POST["submit"]) {
// The message
$message=$_POST["message"];
$email=$_POST["email"];
$headers='From: '.$email."\r\n".
'Reply-To: '.$email;
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('myemail#example.com', 'Quick Pass', $message, $headers );
}
Make sure you getting your form input correctly. then try this.
// recipients
$to = 'to#example.com'; //your email address
$user_email = $_POST["email"]; //input from form
// subject
$subject = 'Subject';
// message
$message = $_POST["message"];
// set conent type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: User Email <'.$user_email.'>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
As previous posters have said, the fourth parameter id for for headers so it should be "From: {$email}" or similar.
However, mail servers are sometimes configured to ignore From headers and set a default value. Also you could find that the message is being ignored somewhere along the email route (by your host's own relay server or by your email provider's incoming mail server) if the sending address doesn't match any DNS MX records for the domain in question. You will need to talk to your hosting provider(s) to investigate this.
I am not good at PHP but still trying to create a test script so that i can learn it. I am referring to w3schools and i don't know how good or bad i am.
I need some changes to be made to what script i just created.
<?php
$to = $_POST['EmailList'];
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
mail($to,$subject,$message,$headers);
print_r($headers)
?>
<html>
<center>
<form method="post">
<br><strong>PHP Email Sender</strong><br><br><br>
Email List<br>
<textarea name="EmailList" placeholder="email#email.com (New Email Each Line)" rows="20" cols="50"></textarea><br><br>
Subject<br>
<input type="text" name="EmailSubject" placeholder="Your Subject Goes Here"><br><br>
Body<br>
<textarea name="EmailBody" placeholder="Write your content (HTML Accepted)" rows="20" cols="50"></textarea><br><br>
<input type="submit" value="Submit!">
</form><br><br>
</center>
</html>
I want some help so that i can send email's to different email's but each email would be in a different line and i would not be using a comma(,). I want the script to generate the comma(,) by its own and carry each email from a new line.
For example i entered 10 emails i need each email to be printed and a message saying sent besides that.
Please let me know if this is possible. I just need some help.
This is tested:
<?php
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
$emailList = explode("\n",$_POST['EmailList']);
if(count($emailList) > 0){
foreach($emailList as $to){
$to = trim($to);
$sent = mail($to,$subject,$message,$headers);
if ($sent){
echo "<p>Sent: $to</p>";
}
else{
echo "<p>Not Sent: $to</p>";
}
}
}
else{
echo "<p>No email addresses</p>";
}
print_r($headers);
?>
i have the following code
$subject = "Subject Here";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Domain Name <domain#domain.com>' . "\r\n";
$to = $email;
$body = '
My Message here
';
mail($to, $subject, $body, $headers);
and it send mail correctly but when i see details in the email in gmail ...
it shows
from Domain Name
to myemail#myemail.com
date Tue, May 25, 2010 at 12:41 PM
subject my subject here
mailed-by mars.myhostingcompany.net
while i want to show my own address in mailed by section so that it should be mydomain.com instead of mars.myhostingcompany.net
There are two types of sender (From), the MIME header sender and the envelope sender.
You send the MIME sender with in the headers in the 4th parameter of the mail() function. You are doing this fine.
The enveloper sender (the one you can send when sending email through sendmail or a sendmail compatible wrapper) with the -f flag, is set in the 5th mail() parameter, additional_parameters, in the format you'd pass it on the command line: -femail#address.tld.
So your mail function would end up looking like this:
mail($to, $subject, $body, $headers, "-fdomain#domain.com");
I take it you're on shared hosting so the reason it shows your hosts email address is because when you configure PHP there is a setting called "sendmail_from" which is a default address to send mail through in the event that no address is provided in your code.
You appear to be specifying the proper headers in your code so I can only think of one possibility (that I can't test from this computer). Try removing the < > around your email address - it may be trying to read that as HTML and so you have nothing. This can occur on Windows machines because PHP itself parses the custom headers and not the MTA (message transfer agent) and PHP treats any < > as HTML.
I realize that it doesn't look as professional (since the email client won't show the name when it receives the email) but if you're running from a Windows machine there's very little else you can do unless you switch to an alternative mail package.
$subject = "Subject Here";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: domain#domain.com' . "\r\n";
$to = $email;
$body = '
My Message here
';
mail($to, $subject, $body, $headers);
//FORM PAGE:
<form method="POST" action="mailer.php">
<p>Please feel free to contact me on the form below or my direct email address: jkench#jasonkench.co.uk<br>
<br><br>
<br>
<br>
<br>
</p>
<table width="327" border="0">
<tr>
<td width="102">Name:</td>
<td width="215"><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td>Company:
<label for="company"></label></td>
<td><input type="text" name="company"></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="email" size="19"></td>
</tr>
<tr>
<td>Telephone No:
<label for="telephone"></label></td>
<td><input type="text" name="telephone"></td>
</tr>
</table>
<p><br>
Enquiry:<br>
<textarea rows="9" name="message" cols="65"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</p>
</form>
//PHP MAILER PAGE
<?php
if(isset($_POST['submit'])) {
//SEND TO
// Send the completed form to the below email address:
$to = "myemail#mydomain.co.uk";
//SUBJECT
// Subject of the email form:
$subject = "Jason Kench - Web Developer";
//NAME
//POST the details entered into the name box
$name = $_POST['name'];
//COMPANY NAME
//
$company = $_POST['company'];
//EMAIL
//
$email = $_POST['email'];
//TELEPHONE NUMBER
//
$telephone = $_POST['telephone'];
//MESSAGE/ENQUIRY
$message = $_POST['message'];
//Headers from a online site may help not sure
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//FROM EMAIL ADDRESS:
// Additional headers to change the FROM EMAIL ADDRESS
$headers .= 'From: Web-Contact-Form#mydomain.co.uk' . "\r\n";
// BODY
// This is the body of the message that will be sent to my email address with their details.
$body = "
You have received a message from the online contact form at http://www.jasonkench.co.uk\n
Details Below: \n \n
From: $name\n
Company: $company\n
$headers
Email Address: $email\n
Telephone No: $telephone\n
Message: $message\n";
// FORM SENT
// This will alert the customer the form has been successfully sent.
echo "Your details have been sent, I will contact you within 48 hours.";
// Use the mail function to email the following variables to my $to email address.
mail($to, $subject, $body, $headers);
} else {
// Display error message if there is a problem.
echo "Sorry there seems to be a problem. Please email me direct at: $to thank you.";
}
?>