Forum Moderators: coopster

Message Too Old, No Replies

How get From Address To Work in php

         

nort99

3:01 am on Aug 3, 2010 (gmt 0)

10+ Year Member



This works with Admin@questionnaire.com showing in the return address. BUT the mail server says it has a bad "Bad file descriptor "
Can you help me with what I have wrong. Here is the php. Thanks for your help.

<?php
ini_set('display_errors',0);
// write all email ids here whom you ant to send emails

please write in the same manner like I have written
$arrEmail = array

('example@example.net','example@example.com')



;
foreach($arrEmail as $email){
$subject="DY Medical Facilities Questionnaire";
// just change

the form action here and write your domain url action like I have written
$mailBodyText =

'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-

equiv="Content-Type" content="test/html;charset=utf-8">

<table border="8"

borderColor="#996600" width="650" height="400">
<tbody>
<tr><td>
<p

align="center"><b><font color="#996600" size="6">DY Medical
Facilities&nbsp;<br>
Learning Tool Questionnaire</font><font color="#996600" size="5"><br>


</font></b></p>
</td></tr>
<tr><td>
<p

align="center"><font color="#996600" size="6"><b>Your Question For Today! </font></p>

<p align="center"><a href="http://www.example.htm">Click
Here!</a></p></b>


</td></tr>
<tr><td>
<p>
</td></tr>


<tr><td>
</td></tr>
</tbody></table>
</form>
</body>
</html>';

$body =

$mailBodyText;
$headers= <<<TTTTTTTTTTTT
From:$from_email Admin@questionnaire.com; $fromAddr
MIME-

Version: 1.0
Content-Type: text/html;
TTTTTTTTTTTT;
mail($email, $subject, $body , $headers);
echo("<br/>Email send to ".$email);
}
?>

enigma1

9:24 am on Aug 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you make sure the headers are formatted properly? They don't look right. Each header must be terminated with a \r\n or \n depending on the transport (smptp or sendmail)

You should have MIME-Version: 1.0 in a single line.

Use the $header variable to add one header at a time like:
$headers = '';
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html' . "\r\n";

It will be easier to setup and read.

rocknbil

3:56 pm on Aug 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, what is $fromAddr? You have stray semicolons and line returns in your header that are mucking up the works.

Try changing just this part to this:

$headers= <<<TTTTTTTTTTTT
From:$from_email
MIME-Version: 1.0
Content-Type: text/html; charset=iso-8859-1
TTTTTTTTTTTT;

or alternatively,

$headers = "From: $from_email\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

If that works,

please write in the same manner like I have written
$arrEmail = array('example@example.net','example@example.com')


If you want to send to multiple addresses, you don't colon-separate, you comma-separate, an array is not needed. I don't think it works with multiple "from's" but you could try it.

$recipients = 'example@example.net,example@example.com';

$headers = "From: $recipients\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

For "send to's," you could retain your original array and loop through. Keep the header changes as above.

$arrEmail = array('example@example.net','example@example.com');

....... etc .......

foreach ($arrEmail as $e) {
mail($e, $subject, $body, $headers);
}

nort99

12:26 am on Aug 4, 2010 (gmt 0)

10+ Year Member



Thanks guys for your help I got it to work.