Forum Moderators: coopster

Message Too Old, No Replies

my php mailer doesn't like multi-line input

mailer page shows up blank and mail not sent

         

HelenDev

11:26 am on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there,

I wrote a little php mailer script which has been working fine up to now, with all types of form input.

I have made a form where the form input has gone into a mysql database, and I am making a page which takes it out again and sends it to the mailer script. This works fine until I try to take the multi-line address out of the db, which makes it all hang and mail not get sent.

I am confused because the mailer works fine with multi-line input straight from a form, but not from the db.

Does anyone have any ideas about how I can fix this?

Helen.

Bigjohn

12:38 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



Show some code?

HelenDev

1:02 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cheers BigJohn.

this is the code in the first page...

// get all the users personal info...
$getuserdata = mysql_query("SELECT * FROM cart_users WHERE UserID='$userinfo'");
$getuserdataArray = mysql_fetch_array($getuserdata);

$contact_name = $getuserdataArray[UserName];
$company = $getuserdataArray[UserCo];
$delivery_address = $getuserdataArray[UserDelAdd];
$invoice_address = $getuserdataArray[UserInvAdd];
$telephone = $getuserdataArray[UserTel];

// send to the mailer
$URL="http://www.foo.co.uk/forms/mailer.php?subject=$subject& contact_name=$contact_name&company=$company&delivery_address=$delivery_address& invoice_address=$invoice_address&telephone=$telephone";
header ("Location: $URL");

this is the code in the next page (mailer script)...

$contact_name = stripslashes($contact_name) ;
$company = stripslashes($company) ;
$telephone = stripslashes($telephone) ;
$invoice_address = stripslashes($invoice_address) ;
$invoice_address = preg_replace("'[\r]'",", ",$invoice_address);
$delivery_address = stripslashes($delivery_address) ;
$delivery_address = preg_replace("'[\r]'",", ",$delivery_address);

//we need to strip out any categories which have been left blank...

if ($contact_name!="") {
$sContactName = 'Contact Name: '.$contact_name."\n";
}

if ($company!="") {
$sCompany = 'Organisation: '.$company."\n";
}

if ($telephone!="") {
$sTelephone = 'Telephone: '.$telephone."\n";
}

if ($invoice_address!="") {
$sInvoiceAddress = "\n".' Invoice Address: '.$invoice_address."\n\n";
}

if ($delivery_address!="") {
$sDeliveryAddress = "\n".'Delivery Address: '.$delivery_address."\n\n";
}

//send the mail...

mail("foo@foo.com,foo@foo.com", "$subject", "$sContactName$sCompany$sTelephone$sInvoiceAddress$sDeliveryAddress ");

[edited by: jatar_k at 5:29 pm (utc) on Mar. 4, 2004]
[edit reason] fixed sidescroll [/edit]

Bigjohn

2:28 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



Try building your body into a single variable:


$msgbod = $stuff

or like I do mine:

$msgsub =<<<END
Thank you {$cname} for your purchase.
We are processing your order for the following:

Item Number:{$itemno}, {$itemdesc}.

You will be contacted via email within 36 hours to confirm your payment
and shipping options. You told us your email address was:
{$cemail}.
If we are unable to contact you via email, you will receive a telephone call.
END;

Thats just a snip of mine. The final line, END; has to be on it's own line with NO WHITESPACE.

Then you just put the one variable on the mail() line.

John

HelenDev

3:43 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cheers John, I have now merged the body variables into one - much neater now ;)

However, I don't think this has solved my original problem. If I enter one line of text into the <textarea> it goes into the db, gets pulled out and mail sent fine.

But if I hit return and add another line and submit the form, mailer page is just blank (it normally displays a thank you message, written in plain html) and the mail does not get sent.

Maybe I should just make the form so the user adds the address a line at a time into an input box?

Helen.

HelenDev

3:44 pm on Mar 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In case anyone is interested, I found a solution:

I used a blob field in the db rather than varchar

I removed all the line breaks and stuff from it before attempting to send the mail...
$enquiry = trim(str_replace("\r\n", " ", $enquiry));

It is now working.

Helen.