adding some text into message in mail - php

$contactname = $_POST['contactname'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = 'Ձեզ գրել են ձեր կայքից';
$to = 'stereoshoots#gmail.com';
$headers = "From: ".$email;
mail($to,$sub,$message,$headers);
I got $contactname (client name). My task is the text like this :
From : $contactname
$message (the text that client wrote).
How should i implant name into text?

You can costumise, the below, but from contact name is in this case, $from
<?php
$to = "someone#example.com";
$subject = "Ձեզ գրել են ձեր կայքից";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";}
else{
echo "Mail not sent";
}
?>

Related

How to set sender's email send from specific domain only?

For example, i only want the sender's email is from "anything#abc.com", if other email like "anything#cde.com" is not allow, only #abc.com is allowed. How should i do that?
let say $_POST['Sender']="anything#abc.com";
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $_POST['Sender'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
you should be able to just wrap it within an if statement:
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $_POST['Sender'];
$headers = "From:" . $from;
if ($from === "anything#abc.com") {
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
You can use PHP's strstr function to strip the first part of the email off (everything before #) like so:
$from = strstr($_POST["Sender"], "#");
if($from == "#abc.com") {
// send mail
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
See http://php.net/manual/en/function.strstr.php for more information on the strstr function

php mail function from a adress with åäö?

Can you send a mail via php from a emailadress with ÅÄÖ?
Like this:
$to = "$email";
$subject = "Test mail";
$message = "Test";
$from = "info#testwithÅÄÖ.se";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

PHP contact form with Freehostia

I cannot get this form to send if I use anything other than $from = 'From: . $email';. If I change it to anything else, it will not send. When it does send with this information, it comes in from .$email#mbox.freehostia.com.
What I would prefer is have the from email address be the email that was submitted in the form, so the receiver can respond without having to create a new email. I've searched everything and can't find an answer to this specific issue.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: . $email';
$to = 'info#resourcedmichigan.com';
$subject = 'ResourcED Career Submission';
$body = "From: $name\nEmail: $email\nPhone Number: $phone\nMessage: $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
include("inc/header.php");
echo '<div class="container"><div class="spacer-top"><h3>Thank you for your interest in ResourcED! We will be in contact with you soon!</h3></div></div>';
include("inc/footer.php");
} else {
echo '<div class="container"><h3>Something went wrong. Go back and try again!</h3></div>';
}
}
?>
Variables will not be interpolated inside of single quotes and the concatenation operator is unnecessary.
$from = 'From: . $email';
should be
$from = "From: $email";
or
$from = 'From: ' . $email;

PHP Email Not Work

i have a website wherein you can inquiry or leave questions and comments and send it via email, the code runs perfectly but it doesn't send email. here is my code:
$myemail = 'albertdaracan#gmail.com';//<-----Put Your email address here.
$fname = "albert";
$lname = "daracan";
$subject = "Magosaburo Inquery Form";
$email_address = $_POST['email'];
$message = "Name: ".$fname." ".$lname;
$message = "test";
$to = $myemail;
$email_subject = $subject;
$email_body = $message;
$headers = "From: $fname $lname <$email_address>\n";
$headers .= "Cc: ";
$headers .= "Reply-To: $email_address";
//redirect to the 'thank you' page
if(mail($to,$email_subject,$email_body,$headers)){
echo "mail successful send";
}else{
echo "Could not send you mail, Please try again later";
}
$message2 = "test";
$to2 = $email_address;
$email_subject2 = "Magosaburo";
$email_body2 = "$message2";
$headers2 = "From: Magosaburo <$myemail>\n";
$headers2 .= "Reply-To: $email_address";
//redirect to the 'thank you' page
if(mail($to2,$email_subject2,$email_body2,$headers2)){
echo "mail successful send";
}else{
echo "Could not send you mail, Please try again later";
}
my other works was fine it send email, but it is in other server...
why not try to fix this issue first
$fname = "albert" //missing semi colon
$lname = "daracan" //missing semi colon
$subject = "Magosaburo Inquery Form"; //terminated here
may be the values were not assigned well which causes the faultness

email address in from field on contact form not showing in email header as "from"

iv added the header field in the form code but when i receive the email, the "from" field in the email shows a garbled code and not the email address of the person who sent the message. This is my message processing code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'I removed my address for privacy on stack overflow';
$fromsubject = 'A message from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for your feedback. I will contact you shortly if needed.<br/>Go to <a href='/index.php'>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.php'>Contact Page</a>";
}
?>
You declared your ^From: header` here:
$headers = "From: $nome <$mail>\r\n";
But it isn't used when you call mail()
mail($to, $subject, $body);
You need to pass $headers as fourth parameter. Else the headers won't take effect
mail($to, $subject, $body, $headers);
You haven't declared $nome anywhere in your code nor $mail in:
$headers = "From: $nome <$mail>\r\n";
And besides that, as this comment mentions, you didn't pass the header into the mail function. See the fourth parameter of the mail function.

Categories