OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

"and" value in PHP

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> "and" value in PHP
Page: [1]
 
 
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
"and" value in PHP - 2/26/2008 22:55:56   
Iam working on my first PHP page and need help with an "and" statement.

My code is
-----------------------------------------
$mail->Body ='Name: '.$_POST['name'];
$mail->Body ='Phone: '.$_POST['Phone_Number'];

-----------------------------------------
but I only get the second value "phone". Is there a way to say
$mail->Body ='Name: '.$_POST['name'] and 'Phone: '.$_POST['Phone_Number'];
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/27/2008 1:32:18   
You should use the concatenate equals, as in ".=" So, something like this should work:
$mail->Body ='Name: '.$_POST['name'];
$mail->Body .='Phone: '.$_POST['Phone_Number'];


_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/27/2008 23:28:44   
Thanks that worked but two quick questions.

1. Would the next line be the same with the "." such as

$mail->Body .='Company: '.$_POST['company'];

2. How would I put line breaks in, such as

$mail->Body ='Name: '.$_POST['name']; <br>
$mail->Body .='Phone: '.$_POST['Phone_Number']; <br>
$mail->Body .='Company: '.$_POST['Company']; <br>


I know my <br> will not work in PHP

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/27/2008 23:56:09   
Yes, just keep using the '.=' to continue to concatenate to the same variable. As you've seen, if you leave off the '.' it replaces the variable with that latest value.

You should be able to use the <br> because it will be inside quotation marks, so something like this:
$mail->Body ='Name: '.$_POST['name'] .'<br>';
$mail->Body .='Phone: '.$_POST['Phone_Number'] .'<br>';
$mail->Body .='Company: '.$_POST['Company'] .'<br>';

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/28/2008 13:25:08   
Hi Brian,

This code is being used in an email and when I put the <br> in I got back the following line an the email I received.

Name: name1<br>Company: company2<br>

Is there any way to have each item on a seperate line?


(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/28/2008 17:03:18   
Sorry, I was thinking it was an HTML email. I think you may need to use either "\n" or "\r\n". So something like this instead:
$mail->Body ='Name: '.$_POST['name'] .'\n';
$mail->Body .='Phone: '.$_POST['Phone_Number'] .'\n';
$mail->Body .='Company: '.$_POST['Company'] .'\n'

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/28/2008 17:38:39   
Still not working,

When I used .'\n'; the body of the email I received was

Name: name1\nCompany: company2\nPhone: phone3Fax:


When I used .'\r\n'; the body of the email I received was

Name: name1\r\nCompany: company2\r\nPhone:

I know I must be missing something simple.
Thanks again for your help.

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/28/2008 22:59:05   
Hmm, I'm missing whatever it is too. Can you supply the php emailer you're using? Maybe it has something different for newlines. If you're not sure what you're using you can post more of your $mail-> code so we can view it (without any email addresses etc.)

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/29/2008 1:00:05   
Brian,
Below is the code I am using. Thanks for taking a look.

------------------------------------------------------------------------------

<?php
require 'class.phpmailer.php';
if(!move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name'])){
echo('file upload error');
}

$mail = new PHPMailer();
$mail->From = 'my@email.com';
$mail->AddAddress("my@email.com","ABC");
$mail->AddAttachment($_FILES['userfile']['name']);
$mail->Body ='Name: '.$_POST['name'].'\n';
$mail->Body .='Company: '.$_POST['Company'].'\n';
$mail->Body .='Phone: '.$_POST['Phone_Number'];
$mail->Body .='Fax: '.$_POST['Fax_Number'];
$mail->Body .='Email: '.$_POST['Email_Address'];
$mail->Body .='Details: '.$_POST['Additional_Details'];
$mail->Body .='Type: '.$_POST['File_Type'];
$mail->Body .='App: '.$_POST['App_Type'];
$mail->Subject = "ABC Order / Quote Request";

if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/29/2008 2:07:01   
Ah, with escape codes, like \n, you need double quotes on your strings, instead of single (I go between PHP and ASP and didn't really pay attention to the difference, but PHP doesn't like to escape with single quotes). Can you try using double quotes instead, and see if it likes it?

$mail->Body ="Name: ".$_POST['name']."\n";

Interesting too, with phpmailer, the $mail->body is supposed to be HTML, and the <br> should have worked. But I'm wondering if they needed to be double quoted too. I don't see why it would need to be double quoted for a <br> tag, but it may just be because it is a string and how the mailer works. I would think the "\n" wouldn't work with html email, but I would try both ways, "\n" and "<br>" if not. Overall though, I think with PHP it may be easier to use double quotes instead of single, unless you have a specific need.


_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/29/2008 14:08:19   
Thanks Brian worked like a charm!!

One last question, is there a way in my php code to direct to another page after the information has been processed? Right now the reply is a blank page with "Message had been sent" . I would prefer to send the user to a page such as "thankyou.htm" which would thank the customer for entering their information and give them a selection of pages to continue on to in our website.

Can a page address be put into the echo line?

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/29/2008 14:32:38   
To redirect to another page you can use the header, location command. Something like this:

header( 'Location: http://www.yoursite.com/thankyou.htm' ) ;

A quick read on it here: http://www.phpf1.com/tutorial/php-redirect.html
(make sure you don't have echo's, html, etc. that would display right before your redirect)

Or you can change your "thank you" text to what you want to display, or place html below your PHP code to display what you want.

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 2/29/2008 15:48:47   
Based upon your suggestion and the info I read from the site linked I came up with the code below and I still get header problems. Any sugestions?

<?php
require 'class.phpmailer.php';
if(!move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name'])){
echo('file upload error');
}

$mail = new PHPMailer();
$mail->From = 'me@mysite.com';
$mail->AddAddress("max@mysite.com","AFS");
$mail->AddAttachment($_FILES['userfile']['name']);
$mail->AddAttachment.($_FILES['Filename2']['name']);
$mail->Body ='Name: '.$_POST['name']."\n";
$mail->Body .='Company: '.$_POST['Company']."\n";
$mail->Body .='Phone: '.$_POST['Phone_Number']."\n";
$mail->Body .='Fax: '.$_POST['Fax_Number']."\n";
$mail->Body .='Email: '.$_POST['Email_Address']."\n";
$mail->Body .='Details: '.$_POST['Additional_Details']."\n";
$mail->Body .='Type: '.$_POST['File_Type']."\n";
$mail->Body .='App: '.$_POST['App_Type']."\n";
$mail->Subject = "ABC Order / Quote Request";

if(!$mail->Send())
{
ob_start();
echo "Test";
header("Location: http://www.mysite.com/error.htm");
ob_flush();
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

ob_start();
echo "Test";
header("Location: http://www.mysite.com/thankyou.htm");
ob_flush();
?>

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 2/29/2008 15:56:08   
You can not have ANY echo's or HTML statements prior to a header statement.

Can you remove any echo's and OB's and give it a try, and supply the error if it still isn't working?

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 3/1/2008 12:50:42   
Brian,

As you propably already figured out I use the above code to process and email with an attcahmment. Is there a way to add more than one attachment using the "." that you showed me. Such as
---------------------------------------
<?php
require 'class.phpmailer.php';
if(!move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name'])){
echo('file upload error');
}

$mail = new PHPMailer();
$mail->From = 'me@mysite.com';
$mail->AddAddress("max@mysite.com","AFS");
$mail->AddAttachment($_FILES['userfile']['name']);
$mail->AddAttachment.($_FILES['Filename2']['name']);

----------------------------------------
Using this code my first file "userfile" attaches just fine but I do not receive the second file attachment "filename2"

Do I need to add something elase?

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 3/1/2008 16:59:33   
For the class addattachment you should NOT use the concatenate period. Just use the addattachment as is for adding as many attachments as needed. Using your example, it should work like this:

$mail->AddAttachment($_FILES['userfile']['name']);
$mail->AddAttachment($_FILES['Filename2']['name']);


_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 3/1/2008 18:03:27   
The file upload is working fine, funny didn't work the first time. As a finishing touch I want to add valiadtion to a couple of the form fields. I read through the post and suggested links and came up with the code below but it does not seem to be working. I would appreciate if you could take a quick look and let me know if I has missed anything. Thanks again for all you help this board and you guys are great!



$mail->Body .='Email: '.$_POST['Email_Address']."\n";
function checkEmail($email_address)
{
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email_address))
{
return FALSE;
}

list($Username, $Domain) = split("@",$email_address);

if(getmxrr($Domain, $MXHost))
{
return TRUE;
}
else
{
if(fsockopen($Domain, 25, $errno, $errstr, 30))
{
return TRUE;
}
else
{
return FALSE;
}
}
}

$mail->Body .='Details: '.$_POST['Additional_Details']."\n";
$mail->Body .='Type: '.$_POST['File_Type']."\n";
$mail->Body .='App: '.$_POST['App_Type']."\n";
$mail->Subject = "AFS Order / Quote Request";

if(!$mail->Send())
{

header("Location: http://www.mypage.com/error.htm");
"Mailer Error: " . $mail->ErrorInfo;
exit;
}


header("Location: http://www.mypage.com/thankyou.htm");

?>

(in reply to ou812)
ou812

 

Posts: 1741
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: "and" value in PHP - 3/3/2008 16:31:59   
I'm not sure what you're saying isn't working for you. My guess is your email address isn't getting validated? It looks like you never call your function. Or maybe you're doing that somewhere else?

_____________________________

-brian

Black Holes suck.

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to Mav44)
Mav44

 

Posts: 228
Joined: 6/25/2006
Status: offline

 
RE: "and" value in PHP - 3/3/2008 16:37:08   
Brian,

Since this validation issue is different from my first issue I started a new post. Please take a look on the board for a email and field validation issue by mav44 when you get a chance. Thanks again for you help!

(in reply to ou812)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> "and" value in PHP
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts