Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having a html form in my wordpress page and i have call action on my form. The file which is calling an action is saved in the root of wordpress directory. sending-mail.php

I have two mail function on the sending-mail.php file one after another and only first function is successfully working not second one.I have tried the wp_mail() function also but same thing is happening with that also.

Following is the code of my php file.

<?php
ob_start();
include("wp-config.php");
$connhandle=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD)or die('can\'t establish connection with mysql');
$dbSelect=mysql_select_db(DB_NAME,$connhandle) or die('could not connect to the database');

$name = $_POST['f_name'];
$email = $_POST['u_email'];
$contact = $_POST['contact'];
$product = $_POST['product'];
$segment = $_POST['segment'];
$how_did = $_POST['how_did'];

$ip = $_SERVER['REMOTE_ADDR'];
$date=date('d M Y h:i A');

$to = "download@somesite.com";
$subject = $email." has downloading a trial version of ".$product;
$headers2 = 'MIME-Version: 1.0' . "\r\n" .
'From: download@somesite.com' . "\r\n" .
'Reply-To:  download@some.com' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n" .
'From: '.$email . "\r\n" .
'Reply-To:  '.$email . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
 $body = "Name:". $name . "<br> Email ". $email . "<br> Phone ". $contact ."<br> Product ". $product . "<br> Segment ". $segment . "<br> How did you hear ". $how_did;
 $sql = "INSERT INTO `downloader_list` VALUES('','$name','$email','$contact','$product','$segment','$how_did','$ip','$date')";

 $msg_body_mailpigeon = "Dear ". $name .",<br>Kindly download from <br> <a href=\"http://somesite.com/file.iso\">http://somesite.com/file.iso</a><br>";
 $msg_body_vpnbee = "Dear ". $name .",<br>Kindly download from <br> <a href=\"http://somesite.com/file.iso\">somesite.com/file.iso</a><br> ";
 $msg_body_spamcheetah = "Dear ". $name .",<br>Kindly download from <br> <a href=\"somesite.com/file.iso\">http://somesite.com/file.iso</a><br>";



mysql_query($sql);

if($product=="mailpigeon"){
mail($email,'trial download',$msg_body_mailpigeon,$headers);
mail($to,$subject,$body,$headers2);
echo "<script>window.location='http://somesite.com/';</script>";
} else if($product=="vpnbee"){
mail($email,'trial download',$msg_body_vpnbee,$headers);
mail($to,$subject,$body,$headers2);
echo "<script>window.location='http://somesite.com/';</script>";
} else if($product=="spamcheetah"){
mail($email,'trial download',$msg_body_spamcheetah,$headers);
mail($to,$subject,$body,$headers2);
echo "<script>window.location='http://somesite.com/';</script>";
}

?>
share|improve this question
1  
The above code looks a typical php code. Please modify and put the code in terms of wordpress. –  Chittaranjan Feb 7 at 6:24
    
i am begginer in wordpress so dont know what should be the code for wordpress site in php. can you give some advice –  Harish Kumar Feb 7 at 6:27
    
Please discard my edit as it was not correct. –  Chittaranjan Feb 7 at 6:38
    
discarded @chittaranjan –  Harish Kumar Feb 7 at 7:06
    
What is the return value of mail or wp_mail? They both return true when successful, and false when they fail. –  Seamus Leahy Feb 8 at 5:10

1 Answer 1

Solved. Actually the problem was not mail() function. The problem was the headers.

I was using the same email address for From: email inside headers. so thats y the first mail function was working properly and the second one was not due to its false header statement.

$headers = 'MIME-Version: 1.0' . "\r\n" .
'From: '.**$email** . "\r\n" .
'Reply-To:  '.**$email** . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

thanks all your guys to make an effort for my question.

But it was a learning experience also that in wordpress we should use the wp_mail() function not the php mail function. There are some plugins available for this which make php mail() function works but better if we use the wp_mail() function

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.