I need senders email id in email subject - php

My php script is running well but i want to send senders address in email subject .Please guide me how to do it.
Please tell me what should i write in "$emailSbuject = "New Subscription from $emailFeild\r\n";"
This is my php script:
<?php
/* subject and email varialbles*/
$emailSbuject = "New Subscription from $emailFeild\r\n";
$webMaster = 'help#sample.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/
$emailFeild = $_POST['email'];
// admin message body
$body= <<<EOD
New subscriber is $emailFeild
EOD;
$textMessage = <<<EOD
<p style="margin-left:5px;font-family:Calibri"><img alt="" src="http://www.intaxfin.com/images/Intaxfin_logo.png"></p>
<p style="font-family:Calibri">Thank you for subscribing with us. Somebody will get back to you as soon as possible.</p>
<p style="font-size:x-small;color:#0099FF;font-family:Calibri">This e-mail was automatically sent by Administration Directory and is for your reference. Please do not reply to this e- mail address.<br>
Powered by sample</p>
EOD;
$headers = "From: $emailFeild\r\n";
$header = "From: $noreply#sample.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
$success = mail($webMaster,$emailSbuject,$body,$headers);
$success1 = #mail($emailFeild,$emailSbuject2,$textMessage,$header);
/*Result*/
$theResults = <<<EOD
EOD;
echo "$theResults";
header("Location: thankyousubscribe.html");
exit;
?>

$emailFeild = $_POST['email'];
$emailSbuject2 = "New Subscription from $emailFeild";
NOTE : $client has been initiated with $emailFeild variable which is initiated after that line. Please initiate the variable first and then use it.

Related

Send mail to multiple friends without knowing that whom I have sent

<?php
$to = "friend1#gmail.com,friend2#gmail.com,friend3#gmail.com,friendn#gmail.com";
$subject = "Anniversay Party";
$txt = "You are invited for a party with classical theme";
$headers = "From: myemail#gmail.com";
mail($to,$subject,$txt,$headers);
echo "<h1>MAIL SENT</h1>";
?>
I am using this script to send mail to my friends but in that everyone knows that to whom I am inviting.
Right now all email address are shown in To field of receipt-ant of mail.
Can anyone help me with that?
<?php
$to = ["friend1#gmail.com", "friend2#gmail.com", "friend3#gmail.com", "friendn#gmail.com"];
$subject = "Anniversay Party";
$txt = "You are invited for a party with classical theme";
$headers = "From: myemail#gmail.com\r\n"; // I added \r\n for best practices
foreach ($to as $email)
mail($email, $subject, $txt, $headers);

How to send image in PHP mail function

I want to send image in mail.How to add image so that it will show in the email
I want to add image to the CLIENT MESSAGE BODY.
How to use html in client message body?
Here is my code :
<?php
/* subject and email varialbles*/
$emailSbuject = 'Enquiry';
$webMaster = 'vivek#a.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/
$nameFeild = $_POST['name'];
$cityFeild = $_POST['city'];
$countryFeild = $_POST['country'];
$emailFeild = $_POST['email'];
$phoneFeild = $_POST['phone'];
$otherFeild = $_POST['other'];
$questionFeild = $_POST['question'];
$commentFeild = $_POST['comment'];
$phone1Feild = $_POST['phone1'];
$hear1Feild = $_POST['hear1'];
$hear2Feild = $_POST['hear2'];
$hear3Feild = $_POST['hear3'];
$hear4Feild = $_POST['hear4'];
$referralFeild = $_POST['referral'];
$otherhearFeild = $_POST['otherhear'];
// admin message body
$body= <<<EOD
Contact Form Details of $nameFeild
Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n
Email: $emailFeild \n
Contact Phone: $phoneFeild \n
Other Phone: $otherFeild \n
Question: $questionFeild \n
Comment: $commentFeild \n
Contact Over: $phone1Feild \n
Known Us through: \n
$hear1Feild
$hear2Feild
$hear3Feild
$hear4Feild
$referralFeild
$otherhearFeild
EOD;
// Client message body
$body2 = <<<EOD
Dear $nameFeild
Thank u for contacting IntaxFin. One of our representatives will contact you the soonest. If you have more questions or information needed, please let us know. We are happy to serve you! \n
-From
IntaxFin Team \n http://www.intaxfin.com \n
Like us on Facebook \n
Follow us on Twitter \n
Connect with us on LinkedIn \n
------------------------------------------------------------------------------------------------- e-mail was automatically sent by IntaxFin Administration Directory and is for your reference. Please do not reply to this e-mail address.
Powered by HexCode Technologies Pvt. Ltd.
EOD;
$headers = "From: $emailFeild\r\n";
$header = "From: $noreply#intaxfin.com\r\n";
$success = mail($webMaster,$emailSbuject,$body,$headers);
$success1 = #mail($emailFeild,$emailSbuject2,$body2,$header);
/*Result*/
$theResults = <<<EOD
EOD;
echo "$theResults";
header("Location: http://www.intaxfin.com/thankyou.html");
exit;
?>
You cannot display images on text/plain emails as shown above. You must send it as text/html.
So you first have to extend your headers like this:
$header = "From: $noreply#intaxfin.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
Then you must update your mailcontent replacing \n or linebreaks with html tags <br> or even <p>
Then you also can include image tags having the image you want to show in the email
<img src="http://www.yourserver.com/myimages/image1.jpg">
This will be downloaded from your webserver when recipient opens it.
.
BUT the much better way will be to use phpMailer Class
Using this, you will be able to include any images IN your email, without need to download it from any website. It is easy to learn and absolutely customizable.
By the way: You should use quotation marks for your $body and $body2 values...
$body= "<<<EOD
Contact Form Details of $nameFeild
Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n"
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<html><head>
<title>Your email at the time</title>
</head>
<body>
<img src=\"http://www.myserver.com/images_folder/my_image.jpg\">
</body>"
mail($email_to, $email_subject , $message,$headers);

PHP mailer change variable based on variable from dropdown menu

I am working on a mailer and form. In my form I have a dropdown menu that is populated from a database. The table in the database has 3 columns: id, facility, and email. I need the mailer side to look at the facility and change $mailto to the corresponding email address from the database. I am really new and this has had me stumped for two days.
Dropdown from form.php:
$queryData = "SELECT * FROM facilities";
$result = mysql_query($queryData);
?>
<select id="cust_Facility" name="cust_Facility">
<?php
while($row = mysql_fetch_array($result))
{
?>
<option value=<?php echo($row['id']); ?>><?php echo($row['facility']); ?></option>
<?php
}
?>
</select>
<?php
?>
Form:
$emailSubject = 'Toner Request';
$mailto = '';
$email = 'Toner Sending Service';
$facilityField = mysql_real_escape_string($_POST['cust_Facility']);
$queryEmail = "SELECT * FROM facilities WHERE ";
$result = mysql_query($queryEmail);
if (isset($facilityField)) {
echo "Facility is set";
}
$body = <<<EOD
<br><hr><br>
Customer Information<br>
<br>
Facility: $facilityField <br>
EOD;
$headers = "From: $email\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Success!</h2>
</body>
</html>
When I hit submit on my form it echoes $facilityField as expected. I don't know what to add after that to make it change $mailto based on what value is in $facilityField. When I set $mailto manually I receive the email as expected.
New mail:
<?php
include('db.inc');
$emailSubject = 'Toner Request';
$mailto = '';
$email = 'Toner Sending Service';
$facilityField = mysql_real_escape_string($_POST['cust_Facility']);
$queryEmail = "SELECT email FROM facilities WHERE facility = '".$facilityField."'";
$result = mysql_fetch_assoc($queryEmail);
echo "$result\n";
if (isset($facilityField)) {
echo "Facility is set";
}
$body = <<<EOD
<br><hr><br>
Facility: $facilityField <br>
EOD;
$headers = "From: $email\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
//$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Success!</h2>
</body>
</html>
I made the changes above according to my understand of Pogrindis' comment. It doesn't echo $result. It just gives me the echo "Facility is set" and "Success!". What am I still missing?
The final working code:
$queryEmail = "SELECT email FROM facilities WHERE facility = '$facilityField'";
$result = mysql_query($queryEmail);
$result = mysql_fetch_assoc($result);
$mailto = $result['email'];
Your body is not in a a string. You should be getting an error.
Your $body var should be something llike :
$body = "<<<EOD
<br><hr><br>
Customer Information<br>
<br>
Facility:". $facilityField ."<br>
EOD";
Then you will be able to use it in your mail function.
At the moment however if the facilty is not set it is still trying to send the email. So an undefined error will occur.
Cleaning if your If statement should help with this.
if (isset($facilityField)) {
echo "Facility is set";
$body = "<<<EOD
<br><hr><br>
Customer Information<br>
<br>
Facility:". $facilityField ."<br>
EOD";
$headers = "From: $email\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
}
else
echo "Please set facility. "
?>
Something a bit more verbose as to what is going on would be helpful also.
Also your $mailto; at the top of the page is not defined.
If you have it on the form you should have an email input (to send to this email.) Or if it to you like a contact page it should be set.
if(isset($_POST['emailFormName']))
$mailto = $_POST['emailFormName'];
The mailto is now set from the form input called emailFormName.
As your update asked how to populate the mailto based on the facility.
You should be using
$mailto = $_POST['cust_Facility'];

send an email using data the user has given in a form?

I have a contact form for my website and am hoping to modify it so that a confirmation email is sent to the user when they click submit. Can anybody advise me on the best way to do this?
My php is pretty simple:
// validation complete
if(isset($_POST['submit'])){
if($msg_name=="" && $msg2_name=="" && $msg_email=="" && $msg2_email=="" &&
$msg2_Message=="")
$msg_success = "Thankyou for your enquiry";
//send mail
$EmailFrom = "someone#somewhere.co.uk";
$EmailTo = "someone#somewhere.co.uk";
$Subject = "Online contact form";
$full_name = Trim(stripslashes($_POST['full_name']));
$Phone_Num = Trim(stripslashes($_POST['Phone_Num']));
$email_addr = Trim(stripslashes($_POST['email_addr']));
}
// prepare email body text
$Body = "";
$Body .= "full_name: ";
$Body .= $full_name;
$Body .= "\n";
$Body .= "Phone_Num: ";
$Body .= $Phone_Num;
$Body .= "\n";
$Body .= "email_addr: ";
$Body .= $email_addr;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
?>
First we get the mailto function to work with localhost and email client:
Check this link on stackoverflow:
URL link: send email to owner by collecting information provided by user through form?
Then I recommend using Swiftmailer. http://swiftmailer.org/docs/sending.html They got the best manual.
As others have already suggested the "if" statement is useless since it is achieving nothing. I think your idea was to verify if the fields that you have in your contact form are filled or not. If the fields are unavailable you should throw some error which you are not doing.
Also, if you are to send a confirmation mail to the user who clicks the submit button then the $EmailTo variable should take the email from $msg_email or $msg2_email which according to the code is not done here.
Check this simple snippet this might help you:
if ($_POST['submit']) {
if ($_POST['name1] == '')
echo "Please provide the first name";
if ($_POST['name2] == '')
echo "Please provide the last name";
if ($_POST['email1] == '')
echo "Please provide the email";
if ($_POST['email2] == '')
echo "Please provide the alternate email";
if ($_POST['message] == '')
echo "Please provide the Message";
//Send email to your inquiry mail with above details
// Confirmation mail
$message =<<<EOM
Dear $_POST['name1'],
Thank you for your inquiry.
Our executives will get back to you ASAP.
Thanks,
Sales
EOM;
$to = $_POST['email1'];
$subject = "Acknowledgement of Inquiry";
$headers = "Content-Type: text-plain";
$headers .= "From: sales#yourcompany.co.uk";
mail($to, $subject, $message, $headers);
}

Sending HTML email, via PHP form

I am trying to send my website visitors and email with some directions and tips before they show up to my studio via PHP form mailer. ( i am simplifying some of the form fields )
However the HTML formatting is not working correctly.... did i not declare the mime type of charset correctly?
<?php
if (isset($_POST['submit'])) {
//if (empty ($_POST['name']) || empty($_POST['email']))
//{
//echo"<div class='error'>Error<br />You did not fill in a required field, please review your form and correct the missing information. <a class='close' href='#'>close</a></div>";
//}
$name = $_POST['name'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
//A bunch of other fields are here
//Additional Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//$yoursite = "My Site";
//$youremail = $email;
$subject = "Website Form";
$message = "
$name would like you to contact them about your service.
Contact PH: $phone
Email: $email
Legal Guardian: $legal
//more stuff here
";
$subject2 = "Directions and Information";
$message2 = "<html><head></head><body>
$message2 .= "<h1>Directions</h1>
<p>text</p>
<p><a href='http://example.com/schedules'>Click here</a>
<h2>How Do I find your Photo Studio?</h2>
<h2>What do I have to bring with me?</h2>
</p>";
$message2 .= "</body></html>";
$email3 = "me#mysite.com";
$email4 = "mysite#gmail.com";
//This email sends their details to me from the visitor
mail($email3, $subject, $message, "From: $email");
//This email sends directions to the visitor from me
mail($email, $subject2, $message2, "From: $email4");
echo"<div class='thankyou'>Thank you for contacting us,<br /> we will respond as soon as we can.</div>";
}
?>
There is a lot of random junk that needs to be done to an email to send correctly. I generally tend to outsource all that responsibility to a pre-packaged class that exists in the wild, something like http://swiftmailer.org/
Maybe someone else would have a better class to offer.
I swear by the PEAR Mail_Mime package. It's simple and powerful.
PEAR: Mail_Mime
//Basic mail headers
$headers['To'] = "test#domain.com";
$headers['From'] = "sender#domain.com";
$headers['Subject'] = "Test";
//Set up the mail module
$mime = new Mail_mime("\r\n");
$mime->setTXTBody("This is a test");
$mime->setHTMLBody("<p>This is a test.</p>");
$body = $mime->get();
$headers = $mime->headers($headers);
//Send the message via SMTP
$mail_obj =& Mail::factory('smtp', array('host' => 'mail.domain.com', 'port' => 25));
$mail_obj->send($headers['To'], $headers, $body);

Categories