Actually I am sending email from php. When I am using file_get_contents() for email body from external file, its not returning email id. Instead email id it's returning '[email protected]'.
Here is my code to call the file with file_get_contents():
$params = 'for=team&name='.urlencode($name).'&email='.urlencode($email).'&phone='.urlencode($phone).'&company='.urlencode($company).'&looking_for='.$looking_for.'&country='.urlencode($country).'&source_page='.urlencode($source_page);
$team_msg = file_get_contents(get_template_directory_uri().'/mail-template/contact_us_email_temp.php?'.$params);
$headers[] = "MIME-Version: 1.0" . "\r\n";
$headers[] .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers[] .= 'From: Someone <someone@domainname.com>';
$to = 'myselft@domainname.com';
$team_subject = 'email subject';
wp_mail($to, $team_subject, $team_msg, $headers );
And Here is the 'contact_us_email_temp.php' which is called from function:
$message = "<table border='0'><tbody>
<tr><td colspan='2'>Users Detail:</td></tr>
<tr>
<td><b>Name</b></td>
<td>".$_GET['name']."</td>
</tr>
<tr>
<td><b>Official Email</b></td>
<td>".$_GET['email']."</td>
</tr>
<tr>
<td><b>Company</b></td>
<td>".$_GET['company']."</td>
</tr>
<tr>
<td><b>Mobile Number</b></td>
<td>".$_GET['phone']."</td>
</tr>
<tr>
<td><b>Looking For</b></td>
<td>".$_GET['looking_for']."</td>
</tr>
<tr>
<td><b>Country</b></td>
<td>".$_GET['country']."</td>
</tr>
<tr>
<td><b>Source Page</b></td>
<td>".$_GET['source_page']."</td></tr>
<tr>
</tbody>
</table>";
echo $message;
I am not sure what's wrong with the function.
Thanks
file_get_contents()
doesn't work like a HTTP Request. You're loading a the ACTUAL file as a string and any code isn't executed. So when you send the mail now, the viewer will see the $_GET['name']
for example. What you want to do is create a function out of the contact_us_email_temp.php
file and use the GET parameters as function parameters.
function getEmail($name, $email, $company, $phone, $looking_for, $country, $source_page) {
$message = "
<table border='0'><tbody>
<tr><td colspan='2'>Users Detail:</td></tr>
<tr>
<td><b>Name</b></td>
<td>".$name."</td>
</tr>
<tr>
<td><b>Official Email</b></td>
<td>".$email."</td>
</tr>
<tr>
<td><b>Company</b></td>
<td>".$company."</td>
</tr>
<tr>
<td><b>Mobile Number</b></td>
<td>".$phone."</td>
</tr>
<tr>
<td><b>Looking For</b></td>
<td>".$looking_for."</td>
</tr>
<tr>
<td><b>Country</b></td>
<td>".$country."</td>
</tr>
<tr>
<td><b>Source Page</b></td>
<td>".$source_page."</td></tr>
<tr>
</tbody>
</table>";
return $message;
}
Require this script in your main script and run the function instead of file_get_contents