Current location: Hot Scripts Forums » Programming Languages » PHP » php mail + html attachments


php mail + html attachments

Reply
  #1 (permalink)  
Old 07-17-06, 03:09 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
php mail + html attachments

hi everyone, well, i came across http://www.programmingtalk.com/showthread.php?t=22506 in this community. i m unable to send attachments with that script. i get the error,
Code:
Fatal error: Call to a member function on a non-object
dunno wats wrong. btw i used the same script thats given in that link. the error is on line 57 of example.php

well, i got one more problem. how can i embedd html tags in a mail ?
this works fine..
PHP Code:

$msg="this works fine";

$email="someone@yahoo.com";
$sendto="someone10@yahoo.com";
$frm="someone";
$subj="Test mail";
$message="
"
.$msg."
"
;
$message=stripslashes($message);
mail($sendto,$subj,$message,"From: $frm<$email>"); 
but i want something like,
PHP Code:

$email="someone@yahoo.com";

$sendto="someone10@yahoo.com";
$frm="someone";
$subj="Test mail";
$message="
<html>
<a href=www.yahoo.com>yahoo</a>
</html>
"
;
$message=stripslashes($message);
mail($sendto,$subj,$message,"From: $frm<$email>"); 
i hv tired of doing things.. i hv been struck here for last 2 days. anyways, thanks in advance..
Reply With Quote
  #2 (permalink)  
Old 07-17-06, 03:24 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
some of them said its cuz, i hvnt initialized the conn. i dunno where to initialize. i dont even know if it works !
Reply With Quote
  #3 (permalink)  
Old 07-17-06, 04:06 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Here's an example on how to send HTML mails.

http://us2.php.net/manual/en/function.mail.php
Reply With Quote
  #4 (permalink)  
Old 07-17-06, 04:29 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
Thumbs up

thanks a lot nico.. that link was helpful.. man.. thanks a lot.. u made my day.. phew!
Reply With Quote
  #5 (permalink)  
Old 07-17-06, 07:08 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
Question i m back with a doubt..

i used this following link and it worked fine with me.
PHP Code:

<?php

// multiple recipients
$to  'aidan@example.com' ', '// note the comma
$to .= 'wez@example.com';

// subject
$subject 'Birthday Reminders for August';

// message
$message '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
   <tr>
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
   </tr>
   <tr>
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
   </tr>
   <tr>
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
   </tr>
  </table>
</body>
</html>
'
;

// To send HTML mail, the Content-type header must be set
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' "\r\n";

// Mail it
mail($to$subject$message$headers);
?>
but i wanna know, can i replace the name, date,month and year here,
Code:
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
with php variables ?
i mean,
Code:
     <td><? echo $name ?></td>
<td><? echo $date ?></td>
<td><? echo $month ?></td>
<td><? echo $year ?></td>
?!? i tried but it doesnt show the variables value at all.. ugh! i never thought this wud happen.. help plzzz ! thanks.
Reply With Quote
  #6 (permalink)  
Old 07-17-06, 07:11 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:



echo date('d'); // Day
echo date('m'); // Month
echo date('Y'); // Year 
http://us2.php.net/manual/en/function.date.php
Reply With Quote
  #7 (permalink)  
Old 07-17-06, 07:21 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
first of all thanks for ur time.. but i m referring to the stored values after retrieving from a table.

PHP Code:

$sql=mysql_query("select * from users",$conn);

while(
$row=mysql_fetch_assoc($sql))
{
$name=$row[username];
$date=$row[joindate];
$month=$row[month];
$year=$row[join_year];

how do i use these variables $name, $date, $month and $year in the html tags of '$message'.
Reply With Quote
  #8 (permalink)  
Old 07-17-06, 07:25 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
This might help - http://us3.php.net/manual/en/languag...g.php#language

Specifically -
Quote:
But the most important feature of double-quoted strings (and HEREDOC) is the fact that variable names will be expanded. See string parsing for details.
and -
Quote:
When a string is specified in double quotes or with heredoc, variables are parsed within it.

There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to parse a variable, an array value, or an object property.

The complex syntax was introduced in PHP 4, and can be recognised by the curly braces surrounding the expression.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #9 (permalink)  
Old 07-17-06, 07:26 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
PHP Code:

<? ob_start(); ?>

<?php
// multiple recipients
$to  'me@yahoo.com'
// subject
$subject 'welcome to my site..';

$name="admin";
$day="2nd";
$month="july";
$year="2006";
// message
$message '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th>
<th>Day</th>
<th>Month</th>
<th>Year</th>
</tr>
<tr>
<td><? echo $name ?></td>
<td><? echo $day ?></td>
<td><?echo $month ?></td>
<td><? echo $year ?></td>
</tr>
</table>
</body>
<html>
'
;
// To send HTML mail, the Content-type header must be set
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

// Additional headers
$headers .= 'To: me <me2@yahoo.com>' "\r\n";
$headers .= 'From: someone <someone@yahoo.com>' "\r\n";
/*
$headers .= 'Cc: [email]birthdayarchive@example.com[/email]' . "\r\n";
$headers .= 'Bcc: [email]birthdaycheck@example.com[/email]' . "\r\n";
*/
// Mail it
mail($to$subject$message$headers);
?>

the above code doesnt work.. it shows null or blank at the places where i m printing php variable values. i m lost..
Reply With Quote
  #10 (permalink)  
Old 07-17-06, 07:27 AM
n3wb!e's Avatar
n3wb!e n3wb!e is offline
Wannabe Coder
 
Join Date: Mar 2006
Posts: 216
Thanks: 2
Thanked 0 Times in 0 Posts
oops.. i m a min late.. lemme check wat u hv given me there... thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Display PHP in HTML page using JS scott2500uk PHP 6 05-18-06 12:25 PM
PHP to generate HTML as loaded from client side mgscom PHP 2 01-14-06 12:02 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
Please help insert html into php idforforums PHP 5 04-06-05 11:29 PM


All times are GMT -5. The time now is 07:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.