Reputation: 312
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 :'( ";
}
?>
Upvotes: 0
Views: 869
Reputation: 2430
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;
.
Upvotes: 1