Ajax form submission error using PHP Mailer - php

I implemented this http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php tutorial on my form, and the form works successfully and displays the thank you div on submission. But the problem is I don't receieve any email, seems like PHP mailer is not working.
Please see the code below
<?php
// Insert your email/web addresses and correct paths
$mailto = 'adil#adilsaleem.co.uk' ;
$from = "web#city.com" ;
$formurl = "http://astonstorlin.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://astonstorlin.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://astonstorlin.co.uk/citycoaches3/thankyou.php" ;
// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);
// Check If Empty
// Add more Validation/Cleaning here...
// Place your Corresponding info here...
$message =
"Pick Point: $pickuppoint\n\n" .
"Destination: $destination\n\n" .
"noppl: $noppl\n\n"
;
// Leave Alone
mail($mailto, $from, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;
?>

I think your headers are not working. $headersep is not defined and moreover please follow :
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($to, $subject, $message, $headers);
Example copied from http://php.net/manual/en/function.mail.php you can refer for more reading this link.

If you are on a shared hosting for example, sometimes they require you to use a fifth parameter like additional_parameters.
mail('nobody#example.com', 'the subject', 'the message', null,'-fwebmaster#example.com');
Check example 3 here: http://php.net/manual/en/function.mail.php

Thank you very much for all your help people, much appreciated.
I got the script working by deleting
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
And the script started working. I have tried using other HTML php mailer but them don't seem to work with this tutorial example for some reason.http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php

Related

Drupal sending mail issue

My problem begins when I had to add a single landing page to an existing Drupal website. I've never worked with this CMS, so I just created a folder for this page in the root folder and put all the content there.
Then it appeared that I need to send mail from this page after submitting a form there. As I understood I can't use drupal_mail() function there, so I tried something like that:
$to = $email;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
But that gave me no result.
Then I installed SMTP auth module for Drupal and tried to send mail, but again I had no result. However, test messages from SMTP module have been sent correctly.
<?php
$to = $email;
$subject = 'the subject';
$message = 'hello';
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "From: $email" . "\n";
$headers .= "Reply-To:: $email" . "\n";
mail($to, $subject, $message, $headers);
?>
Some hosts require you to use an additional parameter, -f, to send mail.
Try:
mail($to, $subject, $message, $headers, "-f".$email);

String "1" gets added in php mail()

I'm sending an email using php's mail() function. My code is as following:
$to = email#email.com;
$subject = "Subject of email";
ob_start();
echo include('emailcontent.php');
$message = ob_get_contents();
ob_end_clean();
$headers =
'From: Email <email#email.com>' . "\r\n" .
'Reply-To: Email <no-reply#email.com>' . "\r\n" .
"Content-type:text/html;charset=UTF-8" . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
For some reason the string "1" is added at the end of the message. This happens in the include('emailcontent.php'), because if I add another string to the message after the include the "1" is added before that addition.
In the emailcontent.php is no 1 or whatsoever.
echo include('emailcontent.php');
Remove the echo. That echo puts 1 in there
You might ask why does echo put 1 in there when its not added anywhere? Because when your file is successfully included the return value of that include is TRUE and when you send that to echo it prints 1. Try
echo 2==2; //1
Why you are echoing the php page? You have to include the page like,
include('emailcontent.php');
Remove the echo it is causing the 1.

Reply to email not working in php

I want to replace default webmaster email from my email it's not working in php script.
I have tried reply-to but it's not working
This is my php code.
$headers= "Reply-To: my#email.com\n";
mail($to,$subject,$body,$headers);
Try a simple structure (source: PHP.net - mail())
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
i don't know about your php-version, but mine doesn't like spaces when concatenetating with .=
try to remove the space here:
$headers .= "Reply-To: my#email.com\n";
so you get:
$headers.= "Reply-To: my#email.com\n";
(giving us information about whether you are getting an error-message and if so, which one - would have helped quite a lot, when my suggestion is right)

PHP - Not Sending Emails with Header Information

I am having a problem sending emails when I add header information.
However when I just remove the header parameter it works. What is wrong? Is it the code? Or some setting I need to change on the web server admin panel to say "Allow-Headers" or something?
I am trying to send to hotmail in case this has any relavance in determining the problem.
Any help would be greatly appreciated. Thanks.
Below Doesn't Send Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message, $headers);
?>
Below Sends Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message);
?>
I use these headers in my php mailing function and it works well. Note: I also use a third party mail-routing service to avoid having my mails marked as coming from a spammy IP. You might want to look into that also.
$headers = 'From: '.$from.'#foo.net' . "\r\n" .
'Reply-To: '.$from.'#foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I also use the optional fifth parameter to mail() to set the envelope address, e.g.:
$parameters = '-f '.$from.'#foo.net';
so the final call is:
mail($to, $subject, $message, $headers, $parameters);
You can just delete the "FROM:" from the headers list .. it prevents it in some hosts .But the real question then will be how ca I change the sent from email address to a specific email that I want

Sending Email in PHP from a button

Let me start by saying I do not have a lot of programming knowledge. I use a program called PHPRunner to generate most of the php that I do. It is mainly for small office stuff nothing fancy.
My question is:
I have a table that has 6 fields one of them called email. When I go into a record I wanted to put a button called "send notification" that would email the record details to the email address associated with that record.
Any help would be greatly appreciated. I know it is probably out here on the web, possibly searching the wrong way.
You can use the mail function in php. Example from the provided link:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
For sending email using PHP, use mail() function
http://php.net/manual/en/function.mail.php
Example:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$from = 'webmaster#example.com';
$headers = 'From: '.$from . "\r\n" .
'Reply-To: '.$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

Categories