PHP - Send Utf-8 E-mail Message Using Php
Hello friends.
First of all note that i'm just an amateur php programmer, so please if what i ask is very dam don't shoot me... I already search the form and found some solutions to send UTF-8 e-mail message using PHP, but for some reason i have to use the above code. The problem is that this code doesn't send UTF-8 e-mail messages. If you can help me please do it. Thank you Code: [Select] <? php $subject = "my subject in UTF-8"; $emailadd = 'mail@mail.com'; $url = "http://www.mySite.com/"; $req = '0'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 40) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 40 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh charset=utf-8 CONTENT="0; URL='.$url.'">'; ?> Similar TutorialsHi, I'm using an excellent script for a guestbook but when I get a notification that someone has signed in the message I get has an error report. The code looks OK to me but there must be something amiss. Here's the code snippet that notifies of a post Code: [Select] if (strtoupper($notify) == "YES") { $msgtitle = "Someone signed your guestbook"; $vcomment = str_replace(""","\"",$vcomment); $vcomment = stripslashes($vcomment); $vcomment = str_replace("<br>","\n",$vcomment); $msgcontent = "Local time : $tgl\n\nThe addition from $vname :\n----------------------------\n\n$vcomment\n\n-----End Message-----"; @mail($admin_email,$msgtitle,$msgcontent,"From: $vemail\n"); } [/codr] The error report says.. [error] XML Parsing Error: not well-formed Location: http://webmail.whatapicture.biz/mewebmail/HooDoo/Servlet/request.aspx?Cmd=GET-MESSAGE&Browser=2&Folder=%2FInbox&ID=3B207097F31F4D1299310AD0591EA8D7.MAI&BODY=0&DT=1305930258851 Line Number 1, Column 284:<BASEELEMENT SCHEMA="MESSAGE" METHOD="GET-MESSAGE"><ELEMENT ID="3B207097F31F4D1299310AD0591EA8D7.MAI"><FOLDER><![CDATA[\Inbox]]></FOLDER><TO><![CDATA[admin@qualitycarersdirect.com]]></TO><SUBJECT><![CDATA[Someone signed your guestbook]]></SUBJECT><RECEIVED>Fri, 20 May 2011 16:52:15 0000</RECEIVED><ATTACHMENTS EXISTS="0"></ATTACHMENTS></ELEMENT><RETURNVALUE>1</RETURNVALUE></BASEELEMENT> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^ [/error] Can anyone help please? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Hi, I'm trying to do the following: Code: [Select] $name = $_GET['thename']; $to = "some@email.com"; $subject = "Subject of Email"; $message = "Click this link: http://mysite.com?$name" $headers = "From: Me" . "\r\n" . "Reply-To: my@email.com" . "\r\n" . "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $message, $headers); The problem I'm experiencing is that the Get function retrieves "/thename=First+Last name", which converts to a broken link in the message (because of the "+" in the url). How would I use urlencode to make sure the Get replaces the + with a %20 in this instance? It doesn't seem that I can use php in the message itself. Thanks! I believe the solution the my problem should be simple I feel that it's staring me right in the face. I have a Cron Job that sends an email message to users who's bill "due date" falls on the current date. I want to make the email more personalized and say:
Dear John Doe:
You have the following bills due today:
Rent
Cable
Internet
Please login to pay your bills
Thanks,.
Here's my following PHP code
<?php header("Content-type: text/plain"); // OPEN DATA BASE define("HOSTNAME","localhost"); define("USERNAME",""); define("PASSWORD",""); define("DATABASE",""); mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die("Connetion to database failed!"); mysql_select_db(DATABASE); joinDateFilter(); // BILL QUERY function joinDateFilter(){ $query = mysql_query("SELECT bills.billname, bills.duedate, bills.firstname, bills.email, bills.paid FROM bills JOIN users ON bills.userid=users.userid WHERE DATE(bills.duedate) = CURDATE() AND bills.PAID != 'YES'"); $mail_to = ""; while ($row = mysql_fetch_array($query)){ echo $row['firstname']." - ".$row['email']."\n"; $mail_to = $row['email'].", "; } if (!empty($mail_to)){ sendEmail($mail_to); } } // SEND EMAIL function sendEmail($mail_to) { $from = "MyEmail@myemail.com"; $message = "Dear " . $row['firstname'].", <br><br>" ."You have the following bills due today.<br><br>" .$row['billname']. "<br><br>" ."Please login to pay your bills"; $headers = 'From: '.$from."\r\n" . 'Reply-To:'.$_POST['email']."\r\n" . "Content-Type: text/html; charset=iso-8859-1\n". 'X-Mailer: PHP/' . phpversion(); mail($mail_to, "Today is your due date", $message, $headers); } ?> Edited by demeritrious, 26 December 2014 - 07:21 PM. My apologize if this should be here since this involves SQL. My user can register himself ( just an email ) to a mail list. He will get a mail after that, but the message in the mail should differ: If there are under 100 people in the DB he should get something like " you are one of the 100 first people ", if there are more then 100 people it should say " sorry, to late ". I can seem to get it to work so help would be awesome ( ps, I kinda need an anwser fast :s ) Code: [Select] $sqlInsert = "INSERT INTO j5_maillist (email) VALUES('$email')"; $sql = "SELECT COUNT(email) FROM j5_maillist AS aantalEmails"; $result = mysql_query($sql); if( mysql_num_rows($result) <= "3" ){ $message = 'you are one of the 100 first people '; } else { $message = 'sorry, to late '; } $to = $email; $subject = 'Nihonto Appreciation Day'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: '.$email.'' . "\r\n"; $headers .= 'From: Nihonto Appreciation Day' . "\r\n"; mail($to, $subject, $message, $headers); return mysql_query($sql); I have a bit of php code to send me an email when someone logs in to my site. I want to include the person's name and two other bits from my database, but I can't get the formatting correct. I keep getting errors when I try to load the page. Here's the code which obviously has mistakes. The first code works, it's the second one that does not work for the $message line .
if (mysql_num_rows($exe) == 1) { $message_m = "Someone with RefCode ".$RefC." has viewed the homepage for the first time."; mail("ray.fellers@gmail.com", "Good News! Someone just logged in to view the home page", $message_m); setcookie("has_entered_correct_refcode", "true", time()+27000000, "/"); setcookie("has_entered_correct_refcode_value", $_POST["refcode"], time()+27000000, "/"); header("Location: /index.php"); die(); if (mysql_num_rows($exe) == 1) { $message_m =" "'.$_POST['fname'].'," with RefCode "'.$RefC.'," and refund amount of "'.$_POST['refvalact'].'," has viewed the homepage."; mail("ray.fellers@gmail.com", "Good News! Someone just logged in to view the home page", $message_m); setcookie("has_entered_correct_refcode", "true", time()+27000000, "/"); setcookie("has_entered_correct_refcode_value", $_POST["refcode"], time()+27000000, "/"); header("Location: /index.php"); die(); }Thanks for any help to resolve this. please help, here is all my code: <div id='div_phone_big'> </div> <head> <script type="text/JavaScript"> function getChoice(val) { yesNo = new Array("Yes", "No"); var getsel = document.contactus.yesnolist.value; var e = document.getElementById("yesnolist"); var strUser = e.options[e.selectedIndex].value; if (strUser == "no") { //alert('lakjdlakjsdlajd'); window.location.href = "http://www.rainbowcode.net/index.php/util/faq"; //document.write(window.location.href); window.location('http://www.rainbowcode.net/index.php/util/faq'); } else { document.contactus.emailreply.value = ""; document.contactus.commtext.value = ""; document.contactus.message.value = ""; document.contactus.commlist.value = ""; } return strUser; } function getCommChoice(x) { comm = new Array("Compliment","Complaint","Feedback","Suggestion","Billing Query","Other"); var getsel = document.contactus.commlist.value; document.contactus.message.value = comm[getsel]; return document.contactus.message.value; } function sayThanks() { alert("Thank you for submitting"); return true; } </script> </head> <body> <form name = "contactus" method="post" onSubmit="return sayThanks()"> <table class='table_format_content_rbc' border='0'> <div> <span class='spn_big_lightblue_rbc'>RAINBOW</span><span class='spn_big_black_rbc'>CODE: CONTACT US </span> <td colspan='3' align='left' class='small_header_rbc'> <h3>Problems and general queries</h3> <li>Phone our call centre on 086 110 6472 ( Available 8am-5pm from monday-friday ) or</li> <li>Email us at <a href="mailto:helloise@pagesalive.co.za">feedback@miranetworks.net</a> </li> </td> </div> <div> <tr></tr> <tr></tr> <tr> <td colspan='3' align='left' class='small_header_rbc'> <h3>Frequently Asked Questions</h3> <li>Please take a moment to read the Frequently Asked Questions as the solution to your query could be waiting for you there!</li> <li>Have you read the <?php echo link_to('FAQ','util/faq') ?> ? <select id="yesnolist" onChange="getChoice(this.value)"> <option value="yes" selected="selected">Yes</option> <option value="no">No</option> </select> </li> </tr> <tr></tr> <tr></tr> </div> <div> <tr> <td colspan='3' align='left' class='small_header_rbc'> <h3>Feedback and Suggestions</h3> </select> </li> <textarea name="message" rows="10" cols="20"></textarea> <br /><br /> <?php $to = "helloise@pagesalive.co.za"; $subject = $_REQUEST["commlist"]; $email = $_REQUEST["emailreply"]; $message = $_REQUEST["message"]; $headers = "From: $email"; mail($to, $subject, $message, $headers); ?> <input type="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </div> </table> <table class='table_format_content_rbc' border='0'> <tr> <td colspan='3' align='left' class='small_header_rbc'> <br/> </td> <tr> </table> </form> </body> and also set the php.ini file portion: ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t and also ran: $ sudo echo "test" | mail -s "test" helloise@pagesalive.co.za The program 'mail' can be found in the following packages: * heirloom-mailx * mailutils please help?? <option value="feedback">Feedback</option> <option value="suggestion">Suggestion</option> <option value="billquery">Billing Query</option> <option value="other">Other</option> </select> </li> <textarea name="message" rows="10" cols="20"></textarea> <br /><br /> <?php $to = "helloise@pagesalive.co.za"; $subject = $_REQUEST["commlist"]; $email = $_REQUEST["emailreply"]; $message = $_REQUEST["message"]; $headers = "From: $email"; mail($to, $subject, $message, $headers); ?> <input type="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </div> </table> <table class='table_format_content_rbc' border='0'> <tr> <td colspan='3' align='left' class='small_header_rbc'> <br/> </td> <tr> </table> </form> </body> and also set the php.ini file portion: ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t and also ran: $ sudo echo "test" | mail -s "test" helloise@pagesalive.co.za The program 'mail' can be found in the following packages: * heirloom-mailx * mailutils please help?? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=344720.0 I am getting an error message. But the program works Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Exam_Online\try.php:3) in C:\xampp\htdocs\Exam_Online\Staff_login_process.php on line 4 Wrong Username or Password my code is <Html> <?php //session_start(); include 'Staff_login_process.php'; MYSQL_CONNECT(localhost,'root','') OR DIE("Unable to connect to database"); @mysql_select_db(Examination) or die( "Unable to select database"); ?> <body> <form action="try1.php" method="post"> <?PHP $query=("SELECT * FROM User u, User_X_Subject us, Subject s WHERE u.Use_Name = '{$_SESSION['username']}' AND u.Use_ID= us.Use_ID AND s.Sub_ID=us.Sub_ID"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=myselect>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> </body> </html> Hi, I got this script which I would like to send a message to all email addresses in the database or send to approved members only. Once I got the first part of this script working I can get the rest to work when sending to approved members. Here is the form which passes the message to the script. Code: [Select] <?php include_once("data/server.php"); $all = 'unchecked'; $approved = 'unchecked'; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['Mailto']; if ($selected_radio == 'all') { $all = 'checked'; } else if ($selected_radio == 'approved') { $approved = 'checked'; } } ?> <div id="pageNav"> <div id="sectionLinks"> <a href="admin.php?cmd=database&username=admin">Database</a> <a href="admin.php?cmd=uploads&username=admin">Uploads</a> <a href="admin.php?cmd=editTemplate&username=admin">Templates </a> <a href="admin.php?cmd=email&username=admin">Email</a> <a href="admin.php?cmd=messaging&username=admin">Messaging</a> <a href="admin.php?cmd=protected&username=admin">Protected Directory</a> <a href="admin.php?cmd=filesanddir&username=admin">Files and Directories</a> <a href="admin.php?cmd=usertracking&username=admin">User Tracking</a> <a href="admin.php?cmd=advanced&username=admin">Advanced</a> <a href="admin.php?cmd=uploads&username=admin">Uploads</a> <a href="admin.php?cmd=subscriptions&username=admin">Subscriptions</a> <a href="admin.php?cmd=applications&username=admin">Applications</a> <a href="admin.php?cmd=searchForms&username=admin">Search Form Builder</a> <a href="admin.php?cmd=categories&username=admin">Categories</a> <a href="admin.php?cmd=phpBB&username=admin">phpBB</a> <a href="admin.php?cmd=mySQL&username=admin">MySQL</a></div> </div> <div id="content"> <div class="page"> <form action=templates/admin/msgtest.php method=POST> <table> <tr> <td>Your Message:</td> <tr><td> </td><td> </td></tr> <tr><td><TEXTAREA NAME="message" COLS=40 ROWS=6></TEXTAREA></td></tr> </table> <table> <tr> <td><input type = 'Radio' Name ='Mailto' value= 'yes' <?PHP print $all; ?> </td> <td>Send Message to all members</td> </tr> <tr> <td><input type = 'Radio' Name ='Mailto' value= 'yes' <?PHP print $approved; ?> </td> <td>Send Message to Approved members only</td> </tr> <tr><td colspan=2><input type=submit name=submit value=Submit></td></tr> </table> </form> </table> </div> </div> </div> And here is the code I have got so far but it doesnt work Code: [Select] <?php include_once("../../data/server.php"); include("../../data/mysql.php"); if (isset($_POST['Submit1'])) { $selected_radio = $_POST['Mailto']; if ($selected_radio == 'all') { $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); $q2 = "select * from games_newsletter "; $result = mysql_query("SELECT email FROM profiles"); while ($email = mysql_fetch_assoc($result)) { $to = $email; $subject = "Test Message"; $body = "This is a test message"; $headers = "From: payments@tropicsbay.co.uk\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { // Redirect back to manage page header("Location: admin.php?cmd=messaging"); } else { echo "Approval Message Failed"; } } mysql_close($con); } } ?> As always, any help is much appreciated Paul Can somebody tell me how to make this exact code send mail? I tested it on my website and it doesn't send any emails. The first code is the file contact_config.php <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> Name: ".$_POST['posName'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Country: ".$_POST['posCountry'] ."<br>Phone: ".$_POST['posRegard'] ."<br>Comments: ".$_POST['posText']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the Name'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $errors_message = 'Please enter the Message'; $errors_subject = 'Please enter the Phone'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> First Name: ".$_POST['posName'] ."<br>Last Name: ".$_POST['posName2'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Telephone: ".$_POST['posRegard'] ."<br>City where jobsite is located: ".$_POST['posText'] ."<br>want us to e-mail you the free Homeowners Guide To Remodeling: ".$_POST['posBox']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the First Name'; $errors_name2 = 'Please enter the Last Name'; $errors_telephone = 'Please enter the Telephone'; $errors_city = 'Please enter the City where jobsite is located'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> The second code is contacts.php <?php include('kcaptcha/kcaptcha.php'); session_start(); require_once("contact_config.php"); if ($_POST['act']== "y") { if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']) { if (isset($_POST['posName']) && $_POST['posName'] == "") { $statusError = "$errors_name"; } elseif (isset($_POST['posEmail']) && $_POST['posEmail'] == "") { $statusError = "$errors_mailfrom"; } elseif(isset($_POST['posEmail']) && !preg_match("/^([a-z,._,0-9])+@([a-z,._,0-9])+(.([a-z])+)+$/", $_POST['posEmail'])) { $statusError = "$errors_incorrect"; unset($_POST['posEmail']); } elseif (isset($_POST['posText']) && $_POST['posText'] == "") { $statusError = "$errors_message"; } elseif (!empty($_POST)) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: $content charset=$charset\r\n"; $headers .= "Date: ".date("Y-m-d (H:i:s)",time())."\r\n"; $headers .= "From: \"".$_POST['posName']; $headers .= "X-Mailer: My Send E-mail\r\n"; mail("$mailto","$subject","$message","$headers"); $_POST['posRegard'] = ""; $_POST['posText'] = ""; $_POST['posCountry'] = ""; $_POST['posEmail'] = ""; $_POST['posName'] = ""; unset($name, $posText, $mailto, $subject, $posRegard, $message); $statusSuccess = "$send"; } }else{ $statusError = "$captcha_error"; unset($_SESSION['captcha_keystring']); } } $cat_name="Contact $store_name manager"; ?> Now for some reason the two of these files are supposed to send me emails when customers click the submit email button on my form but, I don't get any emails. I tested it myself and no emails. Help please! Hi People,
I'm using a php to send an mail using a server via ssl. My program:
<?php Hello, I have been using the mail() command for a while now, but for some reason It has just stopped functioning all together. I have added an OR DIE rule to the end of it and had no response. To all intents and purposes that mail is being sent - there are no errors whatsoever - just the mail is not getting delivered. I cannot think of anything I've done or changed that would stop it from being delivered, I haven't even been near the function that does it in a while. Here is the code: Code: [Select] function sendMail($to,$ref) { $subject = 'Booking Confirmation'; $file = "receipts/$ref.htm"; $fh=fopen($file, "r"); $message = fread($fh, filesize($file)); fclose($fh); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Company <noreply@company.co.uk>' . "\r\n"; mail($to, $subject, $message, $headers); } I have taken out the public names involved, but otherwise thats the code. It has worked absolutely fine in the past, and even If I strip out all of the filehandling part of it, and just use a simple $from - $to - $message, it still seems not actually send the mail. It wouldnt be so bad If I at least had an error to go on, but I dont I am just simply not getting the mail. Please help! ~Chud37 I'm trying to send email with php for the first time. Trying to make it so that after a user registers he/she receives an email after submitting. I'm trying to send it from 1 comp with an email of goldie@telkomsa.net to another with an email of jgoldie@telkomsa.net (I just really want to test if it's sending email another before I get technical with the email) Should this code work, here is part of my code with the email section in it: Code: [Select] <?php // query $sql = "INSERT INTO student (sno, sname, init, fname, title, msname, dob, sex, lang, idno, telh, telw, cel, fax, email, address, contact_flag ) VALUES ('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex','$lang', '$idno', '$telh', '$telw', '$$cell', '$fax', '$email', '$address', '$contact')"; mysql_query($sql) or die('Error:' . mysql_error()); $sno_id = mysql_insert_id(); // get the cid $cname = mysql_real_escape_string($_POST['cname']); $getCID = "SELECT cid FROM course WHERE cname='$cname'"; $result = mysql_query($getCID); if($result) { $row = mysql_fetch_assoc($result); $course_id = $row['cid']; // add the student to the course_student table $addCID = 'INSERT INTO course_student (cid, sno) VALUES(' . $row['cid'] . ', ' . $sno_id . ')'; mysql_query($addCID) or die('Error:' . mysql_error()); // send email $Name = "Da Duder"; //senders name $email = "goldie@telkomsa.net"; //senders e-mail adress $recipient = "jgoldie@telkomsa.net"; //recipient $mail_body = "The text for the mail..."; //mail body $subject = "Subject for reviever"; //subject $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields ini_set('sendmail_from', 'goldie@telkomsa.net'); //Suggested by "Some Guy" if (mail($recipient, $subject, $mail_body, $header)){ echo "mail has been sent"; //mail command } } header( "refresh:5;student_man.php" ); echo 'Registration <b> successful </b> You\'ll be redirected in about 5 secs. If not, click <a href="student_man.php">here</a>.'; } } ?> Email is under the "email section" comment based of what I found on google. I'm not getting any errors so I want to know if the email isn't going through because of my code or my smtp setting etc. I understand you need to use the mail() command but this just wont work for me, my webserver is with godaddy, and they sent me an email saying that i need to use a relay server to send my mail, how do i set this up or anything? Hello, I have those code: $message = " Hello $inforow2['company']<br /> This is a notice about a pending invoice at $inforow3['company'].<br /> If you would like to see the invoice, you can see it <a href='http://$inforow3['url]'/view-invoice?id=$id.php'>here</a><br /> This is an automatic message. Replies will not be monitored.<br /> Yours faithfully<br />$inforow3['company']"; mail($inforow2['email'],"Invoice overdue #1",$message,$inforow3['sentfrom']); I'm not sure if I can send this, and it will get the values from my mysql and put it in the email or it would send the text directly, and if it ill take the html.. Can any one tell me if above code would be correct? this worked and stopped, no error no idea why is this a conflict? Code: [Select] echo("<meta http-equiv = refresh content=0;url=".$url_success.">"); mail($to_supplier, $subject_supplier, $message_supplier, $headers_supplier); $ok = @mail($email_to, $email_subject, $email_message, $headers); Hi, I am using PHP mail() function to sent message. Following is the code, the message is received in email account, but as attachment, not displayed in the body section as normal message would. Please can you guys help, as why is this message going as attachment, but not being displayed in the body of email. Below is the url which gives preview as to what I mean. http://i56.tinypic.com/29fujxf.jpg Code: [Select] $to = $_POST['to']; $subject = ' web visior'; $customer = stripslashes($_POST['customer']); $email = stripslashes($_POST['email']); $contactinfo = stripslashes($_POST['contactinfo']); $body = stripslashes($_POST['enquiry']); $header = 'From:'.$email.'\r\n'; $header = 'Reply-To:'.$email.'\r\n'; $header = 'X-Mailer: PHP/' . phpversion(); $header = 'Content-type: text/html\r\n'; $message = '<html><body> <table> <tr><td>From:'.$customer.'</td></tr> <tr><td>Email:'.$email.'</td></tr> <tr><td>Contact No'.$contactinfo.'</td></tr> <tr><td style="center"><b>Message:</b></td></tr> <tr><td>'.$body.'</td></tr> </body></html>'; Regards, Abhishek Hello, i have this code for sending email it works great but i don't know where to start in sending emails with a pdf file attached ex: test.pdf. Any suggestions? <?php session_start(); require_once('framework/framework.php'); include('framework/class.smtp.inc'); //--- databse settings $dsn = array( 'dbtype' => 'mysql', 'username' => '', 'password' => '', 'host' => '', 'database' => '' ); try { $db = db::connect($dsn); } catch (Exception $e) { die($e->getMessage()); } //--- $subject="Formular online pentru participantii Diaspora Stiintifica 2010"; // +-------------- BEGIN ---- Functia de trimitere mail prin smtp -------------------+ */ function trimite($destinatar='', $subiect='', $mesaj='') { //--- mail settings $smtp_server_host="mail.server.com"; $smtp_server_port="25"; $sender="email@email.com"; $return_path="email@email.com"; $smtp_username="email@email.com"; $smtp_pswd="123"; /*************************************** ** Setup some parameters which will be ** passed to the smtp::connect() call. ***************************************/ $params['host'] = $smtp_server_host; // The smtp server host/ip $params['port'] = $smtp_server_port; // The smtp server port $params['helo'] = exec('hostname'); // What to use when sending the helo command. Typically, your domain/hostname $params['auth'] = false; // Whether to use basic authentication or not // $params['user'] = $smtp_username; // Username for authentication // $params['pass'] = $smtp_pswd; // Password for authentication $params['timeout'] = '60'; /*************************************** ** These parameters get passed to the ** smtp->send() call. ***************************************/ $send_params['recipients'] = $destinatar; // The recipients (can be multiple) $send_params['headers'] = array( "MIME-Version: 1.0", "X-Mailer: PHP/" . phpversion(), "Return-Path: ".$return_path, "From: ".$sender, "To: ".$destinatar, "Subject: ".$subiect, "Content-type: text/html; charset=UTF-8", "Content-Transfer-Encoding: 8bit"); $send_params['from'] = $sender; // This is used as in the MAIL FROM: cmd // It should end up as the Return-Path: header $send_params['body'] = $mesaj; /*************************************** ** The code that creates the object and ** sends the email. ***************************************/ $smtp = new smtp($params); $smtp->connect(); $trimis=$smtp->send($send_params); $raspuns=array($destinatar, $trimis, $smtp->errors); // $smtp->rset(); //--- Bcc: /* $send_params['recipients'] = $sender; $trimisi=$smtp->send($send_params); $errmsgi=$smtp->errors; print "<br>bcc: ".$send_params['recipients']."; ".$trimisi."<br>"; for ($n = 0 ; $n <= count($errmsgi) - 1; $n++) { print "<br>"." bccerr: <strong>".$errmsgi[$n]."</strong><br>"; } */ $smtp->quit(); return $raspuns; } // +-------------- END ---- Functia de trimitere mail prin smtp -------------------+ */ // +---------------------------------------------------------------------------+ $afisez = ""; $cond=0; $query = "SELECT email_1 FROM inregistrari WHERE `completat`=0"; $useri = $db->getAll($query); $i=0; $j=0; $k=0; foreach ($useri as $row) { $tpl = new HTML_Template_Sigma('mesaj'); $tpl->loadTemplateFile("mesaj.html"); $tpl->setVariable($row); $html=$tpl->get(); //*/ $html=nl2br($html); $html=str_replace(chr(10), "", $html); $html=str_replace(chr(13), "", $html); // */ // +----------------------+ $subiect = $subject; if (!empty($row['email_1'])) { $subelements=preg_split("/, /", $row['email_1'], -1, PREG_SPLIT_NO_EMPTY); for ($m = 0 ; $m <= count($subelements) - 1; $m++) { $rez = trimite($subelements[$m], $subiect, $html); if ($rez[1]==true) { $afisez .= $rez[0].";1<br>"; $i++; } else { $afisez .= $rez[0].";0<br>"; $errmsg=$rez[2]; for ($n = 0 ; $n <= count($errmsg) - 1; $n++) { $afisez .= " <strong>".$errmsg[$n]."</strong><br>"; } $j++; } } } else { $afisez .= $row['email_1'].";no email;n<br>"; $k++; } } $afisez .= "<br>{$i} mesaje Trimise<br>"; $afisez .= "{$j} mesaje Netrimise<br>"; $afisez .= "{$k} mesaje fara adresa<br>"; print $afisez; ?> |