PHP - Pear:mail
I am trying to send an email to my gmail account using Mail SMTP.
With the following code: <?php include 'incl/php/Mail.php'; $recipients = 'xxxxxxxx@gmail.com'; $headers['From'] = 'no-reply@newzstand.us'; $headers['To'] = $recipients; $headers['Subject'] = 'Test message'; $headers['Date'] = date('r', time()); $headers['Message-Id'] = '<'. microtime(true).'@newzstand.us>'; $body = 'Test message'; $domain = preg_replace("/.*@([^@]*)/", '\1', $recipients); $mxrr = getmxrr($domain, $mxhosts); $params['host'] = $mxhosts[0]; $params['localhost'] = 'mail.newzstand.us'; $params['username'] = 'no-reply'; $params['password'] = 'xxxxxxx'; // Create the mail object using the Mail::factory method $mail_object =& Mail::factory('smtp', $params); $send = $mail_object->send($recipients, $headers, $body); if (PEAR::isError($send)){ echo $send->getMessage(); }else{ echo 'No error'; } ?> I get the following message: Failed to connect to alt2.gmail-smtp-in.l.google.com:25 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )] Why is Gmail refusing me? Similar TutorialsHello to all out there! this is my first post,so my question may sound a bit simple. :] I am studying PHP and MySQL and I tried to make a mailing form based on a mysql database. My problem occured when I tried to use the PEAR mail object. Here is my code: // THE INCLUDED FILES require_once ("attach_file.php" ); require_once ("Mail.php" ); require_once ("Mail\mime.php" ); //THE VARIABLES TAKEN FROM THE HTML FORM OR JUST CREATED FOR THE CONSTRUCTION OF THE EMAIL $my_email = "something@gmail.com"; $email_subject = mysql_real_escape_string(trim( $_POST['email_subject']),$server_connect ); $email_body = mysql_real_escape_string(trim( $_POST['email_body'] ),$server_connect ); $attached_file = $destination ; // the $destination variable comes from the copy() function in attach_file.php $username = "the_username@gmail.com"; $password = "the_password"; $host = "smtp.gmail.com"; $attach = new Mail_mime(); $attach -> addAttachment($attached_file); $email_body = $attach->get(); $extraheaders = array('from'=>$my_email,'to'=>$email_etaireias,'subject'=>$email_subject,'Bcc'=>$email_etaireias); $headers = $attach -> $headers($extraheaders); // HERE GIVES ME AN ERROR!!! -->Fatal error: Method name must be a string $smtp_info = array('host'=>$host,'auth'=>TRUE,'username'=>$username,'password'=>$password); $smtp = Mail::factory('smtp',$smtp_info); //loop through every single line of the database until there are no more lines with data //and store each line in 3 different variables that i can use while ( $row = mysql_fetch_array($result) ) { $onoma_etaireias = $row['onoma_etaireias']; $email_etaireias = $row['email_etaireias']; $website_etaireias = $row['website_etaireias']; } //construct the mail function . The @ is supressing the errors created .remove it and they will be shown. $mail = @$smtp->send($email_etaireias,$headers,$email_body); As i searched here and there for a solution, i found that it has something to do with the way the mail-mime object creates the body of the email . I also tried to find a solution from the PEAR documentation. do i create the headers someway wrong????? Hi all, Will reading on php.net about the famous mail() function somewhere in the notes, the author mentions to use Pear:: for sending larger amounts of email. Since I have never done anything with pear, I was wondering if it weren't better to start out with Pear, since it's more a long term thinking solution or shoudl i first start with mail(). I have read the Pear pagess, and all I saw were delayed mail sending and sending in larger quantities. If someone could maybe advise me on would could be a best practise i would love to hear The script below works but it goes straight to the junk folder only since i added the parts below to the form. (the form is in another file) How do i stop it from going to the junk folder. Quote $error = $_GET['error']; $httpagent = getenv ('HTTP_USER_AGENT'); $url = $_SERVER['HTTP_REFERER']; Code: [Select] <?php require_once "Mail.php"; $optional = $_POST['optional']; $error = $_POST['error']; $url = $_POST['url']; $httpagent = $_POST['browser']; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $from = "Web server <removed>"; $to = "Admin <removed>"; $subject = "Someone has submitted an error."; $body = "Someone has submitted an error.\n". "Error: $error\n". "URL: $url\n". "Web browser: $httpagent\n". "Anything else you want to add?: $optional\n". "IP: $ip\n"; $host = "removed"; $username = "removed"; $password = "removed"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { header('Location: thank-you.html'); } ?> This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351896.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=314260.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=307948.0 hi, I am trying to send an email with an attachment using PEAR, I have installed PEAR and in my email script I am including teh mail.php and mail_mime.php pages but now I get an error: Fatal error: Class 'Mail' not found in /home/fhlinux129/e/edisongray.com/user/htdocs/PEAR/Mail/mail.php on line 51 Line 51: Code: [Select] class Mail_mail extends Mail { In my code I call PEAR::isError to see if there was an error in the SQL Query so I can log it but its always returning this error. Does anyone know a fix? I have tried to search google it and found http://pear.php.net/bugs/bug.php?id=9950 but it does not say how to fix it. Does anyone have any ideas? Error Non-static method PEAR::isError() should not be called statically $query = "SELECT Column FROM TableName"; $res = $db['database']->query($query); if (PEAR::isError($res)) { $logger->err("Error pulling results from DB. Query:" . $query); } I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://www.phpfreaks.com/forums/index.php?topic=359084.0 When I put all my code in one file, everything runs smooth, as soon as I try to put a chunk of code in a separte PHP file and use an include or require_once I get the error Assigning the return value of new by reference is deprecated in...PEAR\config.php yadda yadda I've done some research and I understand that passing an object by reference (&obj) is no longer acceptable in PHP 5, that's fine, but no where in my code do I have an ampersand, and again, it all works fine if it's all in the same .php file. So i figure i might be doing something wrong with my includes or something. The errors that I am getting are Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111 Code: [Select] include('config.php'); connect(); while ($row = mysql_fetch_assoc($ran_result)) { $ran_image = $row['image']; $category = $row['category']; $last = $row['l_name']; $first = $row['f_name']; $return = $row['item_return']; } echo "<div id='random'>\n"; echo "<h1>Random Signatures</h1>\n"; echo "<img src='../auto_images/$ran_image' /><br />\n"; echo "<p><a href='../auto_pages/signatures.php?c=$category&l=$last&f=$first'>$first $last</a></p>\n"; echo "<p>$return</p>\n"; echo "<br>"; echo "</div>"; ?> Am I doing something wrong with the include? Hello, I have been trying to get my script to draw a barcode but it always outputs a message saying "the image cannot be displayed because it contains errors". I have googled the problem and it seems to be about the headers, I also made sure the "extension=php_gd2.dll" is not commented in php.ini. Could anyone please let me know why this script from pear.php.net can't draw a barcode on my xampp 1.7.7 with php 5.3.8 Code: [Select] <?php require_once("Image/Barcode.php"); header("Content-type: image/png"); Image_Barcode::draw('1234', 'Code39', 'png'); ?> I am trying to use PEAR VALIDATION for a registration form an am not able to get it to work. require 'Validate/US.php'; $email = $_REQUEST['email']; $validate = new Validate(); if (!$validate->email("$email")) { echo "Invalid email"; } is what I am using. and I $email is defined earlier in the code as the user input for email. here is the rest of the code. <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "studentofstone@gmail.com"; $email_subject = "$first_name"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['address']) || !isset($_POST['city']) || !isset($_POST['state']) || !isset($_POST['zip']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $address = $_POST['address']; // required $city = $_POST['city']; // required $state = $_POST['state']; // required $state = $_POST['zip']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } require 'Validate/US.php'; $email = $_REQUEST['email']; $validate = new Validate(); if (!$validate->email("$email")) { echo "Invalid email"; } // $phoneNumber = '$telephone'; $result = Validate_US::phoneNumber($phoneNumber); echo 'Test ' . $phoneNumber .' : <br />'; var_export($result); echo '<br />'; if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" ); header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); $email_message = "Form details below.\n\n"; $email_message = date("m/d/Y") . "\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "address: ".clean_string($address)."\n"; $email_message .= "city: ".clean_string($city)."\n"; $email_message .= "state: ".clean_string($state)."\n"; $email_message .= "zip: ".clean_string($zip)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); header("Location: https://www.paypal.com/"); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <? } ?> This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=349480.0 Hi everybody, I am working with SOAP-PEAR and run on a nasty problem I don't know answer to. First I explain what I know how to do. I am trying to construct a soap request and I know how to do this if XML has this structu Case 1 Code: [Select] <parent> <child1>string</child1> <child2>string</child2> <child3>string</child3> </parent> In this case, I construct an Array("root" => new Soap_Value("child1", "string", "value")).... Now my problem is that I don't know how to create an array() or some other data if XML structure is like this: Case 2 Code: [Select] <parent child1="value1" child2="value2" child3="value3" /> Could somebody please tell me how I can construct a SOAP request with SOAP-PEAR for that structure in Case 2? I just can't find a way to formulate it using arrays or some other data type Your help will greatly be appreciated. Thank you, Victor. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=322457.0 Okay so I am using PEAR's Validate package to validate a few values in my form, it validates the username just fine, but is for some reason returning false on the password field, even if the credentials are correct. Here is the link to the package (http://pear.php.net/package/Validate/) Here is the code: Code: [Select] <?php require("Validate.php");?> <?php require("styles/top.php");?> <?php $validate = new Validate(); ?> <div id="head_reg"> <div id="head_cen_reg"> <div id="head_sup_reg" class="head_height_reg"> <?php require("scripts/newsfeed.php"); ?> <?php require("scripts/links.php"); ?> </div> </div> </div> <div id="content"> <br /> <?php if(isset($_POST['reg-btn'])){ $username = strip_tags ($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['pass']); $repassword = strip_tags($_POST['repass']); if ($username && $password && $repassword && $email){ if($validate->string($username,$options = array( 'format' => VALIDATE_ALPHA, 'min_length' => 6, 'max_length' => 50))){ if($validate->string($password,$options = array( 'format' => VALIDATE_ALPHA, 'min_length' => 6, 'max_length' => 32))){ if ($password == $repassword){ if ($validate->email($email,$options = array( 'check_domain' => 'true', 'fullTLDValidation' => 'true', 'use_rfc822' => 'true', 'VALIDATE_GTLD_EMAILS' => 'true', 'VALIDATE_CCTLD_EMAILS' => 'true', 'VALIDATE_ITLD_EMAILS' => 'true', ))){ $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM users WHERE email='$email'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $pass = md5(md5($password)); $ip = $_SERVER['REMOTE_ADDR']; $date = date("F, d, Y g:i:s A"); mysql_query("INSERT INTO users VALUES ('', '$username', '$pass', '$email','Member', '$date','','0','$ip', '0')"); echo"<center>Thanks, $username! You have completed the registration process and may now login <a href=\"login.php\"><b>here!</b></center>"; } else echo"<center><font color=\"#FF0000\">That email is already in use!</font></center>"; } else echo"<center><font color=\"#FF0000\">That username is already taken!</font></center>"; } else echo"<center><font color=\"#FF0000\">That email is invalid!</font></center>"; } else echo"<center><font color=\"#FF0000\">Those passwords do not match!</font></center>"; } else echo"<center><font color=\"#FF0000\">Your password must be betweed 6 and 25 characters long!</font></center>"; } else echo"<center><font color=\"#FF0000\">Your username must be between 6 and 50 characters long!</font></center>"; } else echo"<center><font color=\"#FF0000\">You did not fill out the entire form!</font></center>"; } ?> <div id="register_form"> <form action="register.php" method="post" enctype="multipart/form-data"> <center> <table> <tr> <td>Desired Username </td> <td><input type="text" name="username" class="textbox" value="<?php $_POST['username'];?>"/></td> </tr> <tr> <td>E-Mail </td> <td><input type="text" name="email" class="textbox" value="<?php $_POST['email'];?>" /></td> </tr> <tr> <td>Password </td> <td><input type="password" name="pass" class="textbox" /></td> </tr> <tr> <td>Confirm Password </td> <td><input type="password" name="repass" class="textbox" /></td> </tr> <tr> <td><p class="register"> <input name="reg-btn" type="submit" class="btn" value="REGISTER" /> </p></td> </tr> </table> </center> </form> </div> <center><a href="#" id="showreg">Why register? Click here</a></center> <div id="content_cen"> <div id="content_sup"> <div id="welcom_pan"> <h3><span>Why</span> Register?</h3> <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus. Curabitur est velit, suscipit eu faucibus eget, aliquam ac enim. per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus.</p> </div> </div> </div> </div> <div id="foot_reg"> <div id="foot_cen_reg"> <ul> </ul> <p></p> </div> </div> </body> </html> This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=320893.0 hi guys im using the pear xml serializer but i am running into a problem, i have a framework for an API which i use to create an array and then output as xml with xml serializer. The issue i have run into: i define a default tag before i create an array so my array is for example array( "a" "b" ) both of these will get labeled video in there xml thats fine <video>a</video> <video>b</video> ok so i have a whole bunch of "videos" with there _attributes set. inside each video i need multiple media elements <media x=2>x</media> <media x=4>x</media> <media x=5>x</media> my problem is that you cant add multiple items to an array with the same Key. array( "media" => x, "media" => x, "media" => x ) and if i let it default then the default tag is video plus i cant set the _attributes of the tag unless i make the value of the key into an array eg. array( "media" => array("_aributes" => array("x" => 1), "mediaValue" => "x"), "media" => array("_aributes" => array("x" => 2), "mediaValue" => "x"), "media" => array("_aributes" => array("x" => 2), "mediaValue" => "x") ) this will give me <media x=2><mediaValue>x</mediaValue></media> <media x=4><mediaValue>x</mediaValue></media> <media x=5><mediaValue>x</mediaValue></media> at the moment i get <video> <media x=2><mediaValue>x</mediaValue></media> </video> <video> <media x=4><mediaValue>x</mediaValue></media> </video> <video> <media x=5><mediaValue>x</mediaValue></media> </video> i want to get <media x=2>x</media> <media x=4>x</media> <media x=5>x</media> any help ? thanks im relay stuck on this one plus my API framework has constraints because it initializes the serializer at the end and inserts the array and parses outputs it even an injection work around would be good but the serializer seems to convert all tags into html char codes regards |