Fasthosts shared platform PHP mail from web page issue -F - php

I am trying to send email from a web page hosted on a shared platform over at fasthosts. I cannot for the life of me get this to work, I had a much more extensive script which checked the validity of email etc, but now I've been reduced to using the basic example from fasthosts and it is still not working.
Please could someone take a look and let me now where I am going wrong...
<?php
// You only need to modify the following two lines of code to customise your form to mail script.
$email_to = "contact#mywebsite.co.uk"; // Specify the email address you want to send the mail to.
$email_subject = "Feedback from website"; // Set the subject of your email.
// This is the important ini_set command which sets the sendmail_from address, without this the email won't send.
ini_set("contact#mywebsite", $email_from);
// Get the details the user entered into the form
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// Validate the email address entered by the user
if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) {
// Invalid email address
die("The email address entered is invalid.");
}
// The code below creates the email headers, so the email appears to be from the email address filled out in the previous form.
// NOTE: The \r\n is the code to use a new line.
$headers = "From: " . $email_from . "\r\n";
$headers .= "Reply-To: " . $email_from . "\r\n"; // (You can change the reply email address here if you want to.)
// Now we can construct the email body which will contain the name and message entered by the user
$message = "Name: ". $name . "\r\nEmail: " . $email . "\r\nMessage: " . $message ;
// Now we can send the mail we've constructed using the mail() function.
// NOTE: You must use the "-f" parameter on Fasthosts' system, without this the email won't send.
$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
// If the mail() function above successfully sent the mail, $sent will be true.
if($sent) {
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$name .' Thank you for contacting us.'));
die($output);
} else {
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
}
?>

Related

how to make email appear in inbox and not junk email (php)

I have written a php mail function to allow a user on my website to fill in a form and send the form to my email. as the question says the email is working once the user send the form however it only appear in my junk email folder instead, i am not a php developer but after doing some research i have noticed a lot people mentione about PHPMailer which i never heard of or used before.
i would much appreciate with a bit oh help.
$to="myemail.com";
//Errors
$nameError="";
$emailError="";
$errMsg="";
$errors="";//counting errors
$name="";
$email="";
$message="";
if(isset($_POST['send'])){
if(empty($_POST['yourname'])){ //name field empty
$nameError="Please enter your name";
$errors++; // increament errors
}else{
$name= UserInput($_POST['yourname']);
if(!preg_match("/^[a-zA-Z ]*$/", $name)){
$nameError="Only letters and white space accepted";
$errors++;
}
}
if(empty($_POST['email'])){
$emailError="Enter email";
$errors++;
}else{
$email = UserInput($_POST['email']);
if(!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email)){
$emailError="Invalid Email";
$errors++;
}
}
if(empty($_POST['msg'])){
$errMsg="Enter message";
$errors++;
}else{
$message=UserInput($_POST['msg']);
}
if($errors <=0){//No errors lets setup our email and send it
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <' . $email . '>' . "\r\n";
$text = "<p>New Message from $name </p>";
$text .= "<p>Name : $name</p>";
$text .= "<p>Email : $email</p>";
$text .= "<p>Message : $message</p>";
mail($to, "Website Contact", $text, $headers);
$success="Thank your message was submitted";
$_POST= array(); //clearing inputs fields after success
}
}
//Filter user input
function UserInput($data){
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Your using the email from their posted variable in your header. When your email server receives this it's going to look like it is spoofed because it is. Your site isn't going to be one of the mail servers setup for that domain.
When setting up MX and DNS records for email you use SPF or key signing to prove who sent the message and that it came from a trusted mail server for that domain. You may want to change the from to be an email and domain you control. You are getting their email in the body anyway.
Worst case if you don't have control over SPF records you could at least mark the from email, assuming it is something you control, as always trusted so it wouldn't go into your junk mail.
$headers .= 'From: <' . $to . '>' . "\r\n";

Contact form in php doesnt receive mail for hotmail

I m trying contact form in php.I receive the mails in gmail,yahoo etc but doesnt recieve any mails in hotmail.I tried a lot but doesnt know whats the problem.Why i cant recieve mail in hotmail? Here is the code.
if (empty($error)) {
$to = 'abc#gmail.com, ' . $email;
$subject = " contact form message";
$repEmail = 'abc#gmail.com';
$headers = 'From: Contact Detail <'.$repEmail.'>'.$eol;
$content = "Contact Details: \n
Name:$name \n
Batch: $batch \n
Email: $email \n
mobile: $mobile " ;
$success = "<b>Thank you! Your message has been sent!</b>";
mail($to,$subject,$content,$headers);
}
}
?>
Check the server admin's email for bounce messages. I would guess it has to do with hotmail rejecting it either because it doesn't like your host or because you don't have SPF or DKIM signing set up. Either way, the blame is probably on your server email administrator more than on your code. Email is actually kinda complex to set up nowadays given all the anti-spam stuff you have to do.
You might want to consider using a third party email service. SMTP through a gmail account or Amazon SES so they'll take care of more of these details. This can be set up by the server admin too, or done in PHP with libraries. Is there a SMTP mail transfer library in PHP
this is more likely
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = 'Order' ;
$message =
'Product Name :'. $_REQUEST['proname']."\n". //these all are example details
'Name :'.$_REQUEST['name']."\n".
'Phone :'. $_REQUEST['phone']."\n".
'City :'.$_REQUEST['city']."\n".
'Address :'.$_REQUEST['address']."\n".
'Quantity :'. $_REQUEST['select'];
if ($email == "" || $subject == "" || $message == "" )
{
echo 'Please fill the empty fields';
}
else{
mail("anything#something.com", $subject,
$message, "From:" . $email);
echo 'Thank you ! we will contact you soon';
}
}

php email script for just email address

Im new to this PHP stuff so please excuse my ignorance
Im after having just one input text box in my flash website where a person just enters there email address and at the click of a button it sends an email to me to a pre defined email address with a predefined subject heading and the email address that was entered in the body of the email
Anyone know of any links or can give some help
all the ones i have found want names email subject message and so on
Any help is appreciated
Mark
EDIT
ok I have the following
In flash I have an input text converted to a movieclip called "addy". Inside the movie clip which has the inputbox which has the variable name "emailaddy"
A Button called "email"
The code i Have running when "email" is clicked is
on (release) {
form.loadVariables("email.php", "POST");
}
the email.php script is as follows
<?php
$sendTo = "mark#here.co.uk";
$subject = "Subscribe to Website";
$headers = "From: Website";
$headers .= "<" . $_POST["addy"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["addy"] . "\r\n";
$headers .= "Return-Path: " . $_POST["addy"];
$message = "Please Subscribe me to Website";
mail(recipient, subject, message, other headers);
mail($sendTo, $subject, $message, $headers);
?>
when I click the button nothing happens
what im after is when the button is clicked for and email to be sent in the following format
To: "mark#here.co.uk"
From: email address specified in text field "addy"
Subject: "Subscribe to Website";
body: "Please subscribe me to Website"
Your help is greatly appreciated
mark
The following code might help:
<?php
$user_mail=$_POST["mail"]; //or $user_mail=$_GET["mail"]; Set to your convenience!
$to_mail="abcde#xyz.com"; //Change to your email address
$message="New user's Email: ".$user_mail; //Change to your requirements
$subject="New user registered"; //Change to your preferred subject
$from="registration#yourwebsite.com"; //Change to your website mail id
mail($to_mail,$subject,$message,"From: $from\n");
To know more about the mail function, please see the documentation.
Well in depth you can do like this
<?php
if($_POST){
$userEmail = $_POST0["emailaddy"]; // textbox variable name comes here
$to = 'abc#xyz.com'; //write down here your email
$subject = 'Subscribe to website'; // your subject goes here
$message = 'Please Subscribe me to Website'; // Mail body message
$headers = 'From: ' . $userEmail . "\r\n" .
'Reply-To: ' . $userEmail . "\r\n" .
'Return-Path: ' . $userEmail; //can send x-Mailer also
mail($to, $subject, $message, $headers);
}else{
echo "Invalid Request";
return false;
}
Don't forget to check first $_POST is happened or not. No need to send Return-path instead of this use x-Mailer which sound good for other mail service providers.
To know more about this read documentation here.
If you want to connect to an SMTP server ,like Postfix or gmail there is a neat php library called PhpMailer.
It is well documentated, so you should be good to go by googleing it :)

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!";

Change email address that sends confirmation email (PHP)

I have a registration page on a site I'm working on. When the person registers for an account it sends an email to the registrants email address with a confirmation link to activate the persons account. The problem is that the "from" email address the registrant receives the email from is: myhostingaccountusername#myhostingprovider###.com.
I want to be able to have the email be: no-reply#mydomain.com.
I'm using PHP and Mysql along with html for the site.
here is my code for sending the email.
// Send the email:
$body = "Thank you for registering at My site. To activate your account, please click on this link:\n\n";
$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$abc";
mail($trimmed['email'], 'Registration Confirmation', $body, 'From: noreply#mysite.com');
How do I do this?
When sending the e-mail to your "registrant" you should set the headers of the mail function in PHP to contain "From" field
for example :
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: no-reply#example.com' . "\r\n" .
'Reply-To: me#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Have you set the From: header for the e-mail?
See http://php.net/manual/en/function.mail.php, example #2.

Categories