want to send session values in url - php

hi i am taking values from a page and getting values in second page whihch is working correctly but i have to send the values in url
<?php
session_start();
$_SESSION["email_address"] = $_REQUEST["email_address"];
echo "Favorite color is " . $_SESSION["email_address"] . ".<br>";
//$errors = '';
$myemail = 'info#abcdef.com';//<-----Put Your email address here.
$to_go="abcdef#gmail.com";
$to = $to_go;
$email_subject = "Contact form submission: aaname";
$email_body = "You have received a new message. ".
" Here are the details: Kindly <a href='localhost/ci/email_wait.php?email_address='.echo $email_address.'&password'=.$password.'>
Click Here</a> to reset your password";
$headers = "From:". $myemail;
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "Mail Sent. Thank you we will contact you shortly.";
?>
NOTE: This code will not work on localhost.

Check out PHP's documentation on string interpolation
You want something like:
$email = "something#somewhere.com";
$body = "Your email address is: $email, hooray!";
echo $body;
Which will output Your email address is: something#somewhere.com, hooray!

Why you echo $email_address and where you initialize your email_address proper way to do like this
$email_body = "You have received a new message. Here are the details: Kindly<a href='localhost/ci/email_wait.php?email_address='".$email_address."'&password='".$password."'>Click Here</a> to reset your password";
and you can also send mail from localhost through smtp settings and put headers also before mail like this
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

Related

How to send different message to admin and user in php

I want to send diifferent email to both admin and user.I dont know how to do that.
The code which i am sharing with you is sending same email to both admin and user.Please help me ..
Here is my code ;
$car = $_POST['category'];
$pick = $_POST['text1'];
$drop = $_POST['text2'];
$source = $_POST['text3'];
$email= $_POST['text4'];
$to="$email";
$subject="Web Enquiry";
$message="Hi,". "\r\n" . "\r\n" .
"You've received an email with following details, from the inquiry made at the website- mail#silvertaxi.com" ."\r\n"."\r\n".
"Car Category:"." "."$car"."\r\n".
"Source Location:"." "."$pick"."\r\n".
"Destination Location:"." "."$drop"."\r\n".
"Day and Time.:"." "."$source". "\r\n".
"Email:"." "."$email". "\r\n" ."\r\n".
"Thanks & Regards,". "\r\n" .
"Web Admin"."\r\n" ;
$headers ="From:$email\n";
$headers .= 'Cc: admin#email.com' . "\r\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";
if(mail($to, $subject, $message,$headers))
{
echo "Your Message has been sent." ;
} else {
echo "";
}
You should call mail() function twice; one for user and another for admin. Remove the line
$headers .= 'Cc: admin#email.com' . "\r\n";
from your code.
Then, define different messages for user and admin as you want.
$to="$email";
$subject="Web Enquiry";
$message="....." //your message to user goes here
$to_admin = "admin#email.com";
$subject_admin = "...."; //subject for mail to admin
$message_admin = "....." //your message to admin goes here
Use the mail() function twice to send different emails.
if((mail($to, $subject, $message,$headers) && mail($to_admin, $subject_admin, $message_admin, $headers))
{
echo "Your Message has been sent." ;
} else {
echo "";
}
firstly you need to check he is user or admin. If he is user you can add a condition statement for its another for admin. Like this:
if($user_role == "user"){
//mail for user
.....
}
if($user_role == "admin"){
//mail for admin
.....
}
If you have any question feel free to ask.

PHP send Multiple email not working

In my following code it working fine for one email id but when I changed $to with two email id like $to = "test1#gmail.com,test2#gmail.com" then it not sent email to receptions emails.
$to = "test1#gmail.com";
$subject = "Student details";
$msg = "Body Message here";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if(mail($to,$subject,$msg,$headers))
{
echo "email sent successfully";
}
Might be this question look like silly but it difficult for me to debug why it is not working for multiple email.

Php mail. Can't get email on one address

I have a problem with my mail in php. I code form to send email. I receive email on gmail but I have other mail address and I can't get email on it.
I checked in spam and there is no email also.
Below is my code.
<?php
$emailErr = "";
$endMessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Proszę uzupełnić pole e-mail";
}
else if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$namesurname = $_REQUEST['name_surname'] ;
$email = $_REQUEST['email'] ;
$number = $_REQUEST['number'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$message = $subject . ": " . $message . " " . $number . " " . $namesurname . " " . $email;
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
mail("szafor#szafor.pl", "Zamówienie pomiaru",
$message, "From: formularz#szafortest.pl \r\n"."Content-Type: text/plain; charset=UTF-8\r\n");
$endMessage = "Dziękuję za przesłanie wiadomości.";
}
}
?>
One important thing to consider with sending mail is that you should at least have the return path of the message be an email address that is actually hosted on the server that you are sending from.
You can set the From and the Reply-To address as any address, but the return-path should be set to a valid email address hosted on your server. Let's say that you want the "reply" button to send back to "this_email#wherever.com" but the server you are using hosts email for "mydomain.com". Create an email account on your server, "info#mydomain.com" for example.
$recipient = "sendto#email.com";
$subject = "Test email";
$message = "This is the message.";
$headers .= "From: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Reply-To: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Return-Path: Your Name Here <info#mydomain.com>\n\r";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .="X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
mail($recipient, $subject, $message, $headers);
I have found that the more valid header information that I provide, the more likely the email will be delivered. Right now these headers always work for me, and I have a scheduling program that is sending email to a hundred different email addresses every day. See if that works better for you.

PHP - Email is not sending

There are two steps first the email i sent to the person who wants the newsletter and the second email needs to be sent to info#dirtytrend.com. The problem is that the email is sent in the first step but the email in the second step is never getting through but the code seems to carry on without any errors.
The code is below
<?php
$name = $_POST["nameofperson"];
$to = $_POST["emailofperson"];
$subject = "Hi!";
$body = "Hi " . $name . ",<br><br>Thank you for subscribing?\n\nWe have logged your email to process your newsletter and you will recieve an email from us confirming your subscription.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (mail($to, $subject, $body, $headers)) {
$body2 = "Name: " . $name . "\n";
$body2 .= "Email: " . $to;
if(mail("info#dirtytrend.com", "Subscription Request", $body2)){
header("Location: http://www.dirtytrend.com/events.html");
}
else{
}
} else {
echo "ERROR: Email not sent please contact the system administrator";
}
?>
In the second mail() you have only 3 parameters and you're missing the 4th one with the headers so maybe it is recognized as spam?

Warning: mail() [function.mail]: SMTP server response: 550 Invalid recipient:

I'm creating a 'forgot password' page where the user enters their email address and the script finds the password associated to that email, and sends it to the stored email address.
I believe the problem has to do with my SMTP Mailserver. I am using WAMP which doesn't have one so I downloaded one that was free.
This is the php script I'm using:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = #mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
The $msg outputs properly so I know the code is passing the mail function.
Try sending in a proper "From" in $header.
$emailFrom = "admin#yourdomain.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
See details of the mail() function.
If this doesn't work, try using PHPMailer. You configure it in code, no need to edit php.ini.
I've used it in some projects (v 2.0.4, I see the latest is 5.1) and had no problems.
Try using Google's server to send mails, you can see how to do that here
Try using this
//Email information
$to = "garggarima#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support#sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";

Categories