The aim of this script is to send an email, but instead of including your name and email, it would include it on the message because the website already has details of this from the PHP session. Currently the "2Email" works.. it can send a message to the recipient's mail box, and includes the user's input message. But it doesn't follow the template. I.E. It doesn't include the text "Sent via the dashbaord"
<?php
session_start();
if(!isset($_SESSION["USER"])){
header("Location: ../login.php?NotAuth");
}
$to = $_POST['2Email'];
$name = $_SESSION["USER"]["FullName"];
$email = $_SESSION["USER"]["Email"];
$subject = $_POST['regarding'];
$message = $_POST['msg'];
$Cc= $_SESSION["USER"]["Email"];
$headers = "From: $email";
$tracker = "This message was sent via the TrackerSystem dashboard";
$message = "Hi, "."\n".$message. "\n". "Regards, ".$name. "\n".$tracker.
$sent = mail($to, $subject, $message, $headers) ;
if($sent) {
print "Sent successfully! XD ";
} else {
print "The server made a booboo, the email didn't send :'( ";
}
?>
Is it a typo on line 19: "\n".$tracker. ? If so, that's what prevents your tracker being appended to the message.
What's actually happening: the whole expression on lines 19-20 (this one):
$message = "Hi, "."\n".$message. "\n". "Regards, ".$name. "\n".$tracker.
$sent = mail($to, $subject, $message, $headers) ;
is being evaluated from right to left (if it even works, of which I doubt). So (first) mail is sent and result is assigned to $sent and (second) the whole concatenated string is assigned to $message.
To fix it, make "\n".$tracker. "\n".$tracker;.
Related
The first code without $_Post works, the second one with $_POST doesnt. It is on the server in cpanel. Anything helps :)
I tried various things like changing the code in HTML, placing slashes, also using $_request over $_post.
This works -
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Hi,nn This is test email send by PHP Script";
$headers = "From: me#example.hr";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Poruka:$_POST[poruka]";
$headers = "From: $_POST[email]\n";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
</code></pre>
The first code sends the email, while the second one goes into echo ("Email sending failed...")
I am using this simple php mail function and I would like to add to message another text like "this message is from website".
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$message=$_POST["message"] + $sitemessage;
$sitemessage= "this is message from website";
mail ($email, $subject, $message, "From:".$from);
I tried to add another variable and put it into mail function but it doesn't work.
Use . to concatenate (not +) and $sitemessage should be appended to $message after it has been assigned a value.
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$sitemessage= "this is message from website";
$message=$_POST["message"] . $sitemessage;
mail ($email, $subject, $message, "From:".$from);
This code will simply do what you want.
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$headers = "From: $from ";
$message=$_POST["message"];
$message .= " this is message from website";
mail ($email, $subject, $message, $headers);
I'm getting trouble with my php code.
I have a table named: prof_ales with 3 columns: cnp, evaluat and evaluator.
And a button "Send Email".
When the client press the button I want to send an email to 2 specific email adresses which are already saved into my table "prof_ales" in the column "evaluator".
Here is my code, and for now it's working, but the message is send only at the last email adress.
<input class="buttom" name="submit" id="submit" tabindex="5" value="Send Email" type="submit">
<?php
if(isset($_POST['submit'])) {
$interogare = ("SELECT * FROM prof_ales WHERE cnp='".$_SESSION['sess_user']."'");
$rezultat = mysql_query($interogare);
while ($rand = mysql_fetch_assoc($rezultat)) {
$ev= $rand['evaluat'];
$to = $rand['evaluator'];
}
$message = "test email ";
$subject = "Received from $ev";
$body = <<<EMAIL
Etc etc
$message
Bla Bla
EMAIL;
$header = "From: quabits.ro";
}
if($_POST){
mail($to, $subject, $body, $header);
echo "Sent";
}
?>
As I said I want to send to both(or more) email adresses any time when button is pressed. Tks.
As already said above you need to put the call of the mail() function inside the while()-loop. Using correct formating makes the code easier to read:
while ($rand = mysql_fetch_assoc($rezultat)) {
$ev= $rand['evaluat'];
$to = $rand['evaluator'];
$message = "test email ";
$subject = "Received from $ev";
$body = "Test";
$header = "From: quabits.ro";
if($_POST) {
mail($to, $subject, $body, $header);
}
}
You must put the code to send the email in the while loop. So it would be:
<?php
$connect = mysqli_connect("","","","");
if(isset($_POST['submit'])) {
$interogare = ("SELECT * FROM prof_ales WHERE cnp='".$_SESSION['sess_user']."'");
$rezultat = mysqli_query($interogare,$connect);
while ($rand = mysqli_fetch_assoc($rezultat)) {
$ev= $rand['evaluat'];
$to = $rand['evaluator'];
$message = "test email ";
$subject = "Received from $ev";
$body = <<<EMAIL
Etc etc
$message
Bla Bla
EMAIL;
$header = "From: quabits.ro";
}
if($_POST){
mail($to, $subject, $body, $header);
echo "Sent";
}
}
?>
The code you wrote just meant:
select the first email from database and save it into a variable.
Replace the value into the variable with the second email. Send a mail
to the address in the variable.
The improved version means:
select the first email from database and save it into a variable. Send a mail to the address in the variable.
Replace the value into the variable with the second email. Send a mail
to the address in the variable.
I have a form that people fill out. It sends me an email when they submit. I want the email to show it is from the person sending it. Their email is one of the fields. I want to be able to hit reply to reply to them.
This is the code I am using:
mail($_POST["e_mail"]."myaddress#email.com", $_POST['e-mail']." Interested in Cajun Catering", "Name: ".$_POST['Name'] ."\n"."Address: ".$_POST['address']."\n"."City: ".$_POST['city']."\n"."E-Mail: ".$_POST['e_mail']."\n"."Phone: ". $_POST['phone']."\n"."Time to call: ".$_POST['call']."\n"."Products: ".$_POST['Prod1']." ".$_POST['Prod2']." ".$_POST['Prod3']." ".$_POST['Prod4']." \n"."Type: ".$_POST['type']."\n"."Event Date: ".$_POST['event_date']."\n"."Number of Guests: ".$_POST['Number']."\n"."Comments: ".$_POST['comments'],'From: '.$_POST['e_mail']);
You could try using the -f option with mail():
$to = "youremailaddress#email.com";
$subject = "The subject";
$message = "The message";
$from = "FROM: returnaddress#email.com";
$return = "-freturnaddress#email.com"
mail($to, $subject, $message, $from, $return);
Note that $return contains the same email address as $from, preceded by -f
So what I want to do is get the email they filled the forum in with and then send a message to that email they filled in here's what I have: it says its sent but I never get the message:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: My Contact Form';
$to = '$email';
$subject = 'Folio Message';
$body = "Hello";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<center><font color="lightgray"><p>Message Sent Successfully!</p><script type="text/javascript"> function leave() { window.location = "http://webdesign.about.com"; } setTimeout("leave()", 3000); </script></center>';
} else {
echo '<center><font color="lightgray"><p>Ah! Try again, please?</p></font></center>';
}
}
?>
So i have $to = '$email'; so by doing that it should read the email that was filled in right? Idk my PHP skills are weak
any idea's? or advice?
Thank you in advance kind people!
Remove the apostrophes from the $to = '$email';
It should be $to = $email;
With the apostrophes, your $to variable is being set to the string "$email" and not the email that the user entered.
Drop the single quotes around $email, so your code looks like this: $to = $email;.
PHP evaluates content in single quotes as a literal string, without interpreting any variables. So, it is literally using the text $email as the recipient's email address.
Two things here:
From header should contain valid mail address. E.g.
$from = 'From: youraddress#domain.com';
As others said fix the single quotes. You can just use $email in mail call like
mail ($email, $subject, $body, $from)
On a different note, consider sanitizing your POST parameters. Especially if your script is on publicly available site.