473,791 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML mail send in php

7 New Member
Hi all, i am new in php, I looked lots of example from Forum and tried online server but its nt work at all, i know i may be doing great mistake to sending HTML mail. last time i tried this code beloo, pls give me idea what is the erroe and its say "Mail Failed'

<?php
$to = 'example@test.c om';
$subject = 'Test HTML email';
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@examp le.com\r\nReply-To: webmaster@examp le.com";
$headers .= "\r\nConten t-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash. "\"";

//define the body of the message.

ob_start(); //Turn on output buffering
?>

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
what i need to do clearly if i want to send HTML email?
&
what need to do for testing on my PC in xp OS
&
what i need to do on real server when i will keep it?
Thx a lot
Jan 22 '08 #1
7 3483
Markus
6,050 Recognized Expert Expert
Take away the '@' symbol before $mail_sent to stop it supressing any errors.

See if it now shows you an error
Jan 22 '08 #2
redblue
7 New Member
Take away the '@' symbol before $mail_sent to stop it supressing any errors.

See if it now shows you an error
Hi,
I removed @sybbol still same problem, do i need to edit or do something on server? sorry i have no idea abt this, Thx a lot
Jan 22 '08 #3
stepterr
157 New Member
Hi,
I removed @sybbol still same problem, do i need to edit or do something on server? sorry i have no idea abt this, Thx a lot
RedBlue,
I just tried it on my server and the code is working, even with the @ symbol. So unfortunately it isn't something easily detectable in your code. How are you trying to run this on your PC?
Jan 22 '08 #4
redblue
7 New Member
RedBlue,
I just tried it on my server and the code is working, even with the @ symbol. So unfortunately it isn't something easily detectable in your code. How are you trying to run this on your PC?
Hi Stepterr,

I just run on my pc simpley as any php file. also on the srever same. i mean is it anything to do i mean some edit or change on server? pls tell me ? i never done mail related thing on web. Thx a lot

after test on my pc windows xp OS: the eroor is :
Fatal error: Call to undefined function: ob_get_clean() in C:\apache\htdoc s\email\mail.ph p on line 30
and online server is : fail to send!
Jan 22 '08 #5
stepterr
157 New Member
Hi Stepterr,

I just run on my pc simpley as any php file. also on the srever same. i mean is it anything to do i mean some edit or change on server? pls tell me ? i never done mail related thing on web. Thx a lot

after test on my pc windows xp OS: the eroor is :
Fatal error: Call to undefined function: ob_get_clean() in C:\apache\htdoc s\email\mail.ph p on line 30
and online server is : fail to send!

Do you know what version of PHP you are using? ob_get_clean() is a standard function since PHP 4.3.0. That's probably what the issue is. To get around this you could just add the following code.

[PHP]
<?php
if (!function_exis ts("ob_get_clea n")) {
function ob_get_clean() {
$ob_contents = ob_get_contents ();
ob_end_clean();
return $ob_contents;
}
}
?>
[/PHP]

While this should help you get through, you may still want to get a newer verison to keep yourself from getting hung up on other things as well.
Jan 22 '08 #6
redblue
7 New Member
Do you know what version of PHP you are using? ob_get_clean() is a standard function since PHP 4.3.0. That's probably what the issue is. To get around this you could just add the following code.

[PHP]
<?php
if (!function_exis ts("ob_get_clea n")) {
function ob_get_clean() {
$ob_contents = ob_get_contents ();
Hi Steperr,
I included this code u provided , Now there is no error like before , but say "mail failed" i mean mail cant sent?
Jan 22 '08 #7
redblue
7 New Member
Hi Steperr,
I included this code u provided , Now there is no error like before , but say "mail failed" i mean mail cant sent?
Hi Steperr,
I think a little problem now, I really cant understand why its say Mail faild? for sending mail should i make change any properties of any file on server or on my PC? Thx
Jan 24 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
5315
by: LRW | last post by:
I'm not sure this message is totally appropriate for this group, so please, if anyone has a better group suggestion, let me know! My company sends out a monthly newsletter in HTML format to our account holders. We get a couple of people with auto-responders saying they don't accept HTML e-mails, please send plain-text. Is there some way to format an e-mail with both versions, maybe defaulting to HTML format but display plain-text if it...
3
481
by: T.Michelle | last post by:
We have few Mail templates (.html) which we use to send mails. We want to have some Logo in that ie ... when I send the mail to user the image should go as in-line embedded image in mail. I am not able to get this. I tried with
4
2974
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text email by creating a text file, with content following certain format, and saving that file into the correct '..\mailroot\pickup' folder, and it is working fine
5
2334
by: Thierry | last post by:
Hello. Is it possible to send an email with some HTML code ? I tried the following code, where $msg == '<html><body>... blah blab blah etc.</body></html>' : // Adresse de l'expediteur $entete = "From: $from \n";
4
7552
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP SP2, and IIS's SMTP and WWW servers are installed. Here is the error trace: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an...
4
1614
by: Jim in Arizona | last post by:
Now that I've figured out how to send mail within our domain: Dim test as new System.Net.Mail.SmtpClient Dim nco as New System.Net.NetworkCredential("mailaccount","password","domain") test.Credentials = nco test.Host = "mailserver" test.Send("mailaccount@domain.local","toaccnt@domain.local","Subject","Message") I am wondering how I could send mail in HTML format, or any other format
6
5938
by: =?Utf-8?B?TMOhemFybw==?= | last post by:
Hi everyone I've a simple ASP.NET Page that send a email using smtclient. The server is a Exchange and use my credentials to autentificated. The problem is that the send mail appear in the junk email folder. Any idea. Thanks
3
100096
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg You can make your emails fancy in Mail.app by using Rich Text formatting or even included Stationery. But, a simple way to send your own HTML creation (or any web page for that matter) is to use Safari. Follow these four easy steps. 1. Create the HTML Layout your HTML code including any images or graphics you'd like to include. In this example, we will make a simple birthday email to add...
2
18174
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
0
3214
by: kronus | last post by:
Hey everyone, I am stumped once more and you guys have always helped in one way or the other. I am just now starting to fool around with using PEAR to send html emails. Following the sample scripts -- http://www.phpmaniac.net/wiki/index.php/Pear_Mail#Sending_to_multiple_recipients -- I was able to send html emails with no problem. However, when I applied these concepts to a dynamically generated email, the recipients would receive an...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.