PHP - Moved: Pear Mail With Gmail Smtp
This topic has been moved to Other Libraries and Frameworks.
http://www.phpfreaks.com/forums/index.php?topic=307948.0 Similar TutorialsThis 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=351914.0 Here i have attached PHP contact form.Anyone filled this form and then need to go email to the admin . as example admin uses example@gmail.com as his email address... how can i do this ? in simply when i filledout this form and click Submit button then that information need to go admins email address(example@gmail.com ) Thanks [attachment deleted by admin] Hello 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????? $to=sammieave@ave.com,samuel@ave.com; $subject = "New Event Logged"; $message = "Test"; $headers = "From: Samuel<sammieave@ave.com>;\r\n"; $headers .= "Content-Type: text/html"; mail($to,$subject,$message,$headers); I am having the above code but unfortunately the error I am getting is: Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\xampp\htdocs\CRM\support\mailer.php on line 139 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? 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'); } ?> Using the attached code below I'm sending an HTML email using PHP. It works fine, except with Gmail. If the email is sent to a Gmail account the email contents are blank and sender is unknown. I've looked around and it seems there is some widespread issue but i haven't found an answer/solution. Any help or light shed on this would be great. <?PHP //lots of stuff before this including variable setting, which all are working properly $to = $email; $subject = 'Your claim is in process!'; $random_hash = md5(date('r', time())); $headers = "From: The Insurance Agency\r\nReply-To: info@XXXXXXXXXX.com"; $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; ob_start(); ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Dear <?PHP echo $fname?>, Thank you for submitting your claim on our website. We're sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.Sincerely, Brian R Miller, Priciple --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <img src="http://beta.XXXXXXX.com/img/uniform/emailhead.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 5px 0;">Dear <?PHP echo $fname ?>,</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0;">Thank you for submitting your claim on our website. We're sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px 0 0 200px;">Sincerely,</p> <p style="margin: 10px 0 0 200px;"><img src="http://beta.XXXXXX.com/img/uniform/briansig.gif" alt="" /></p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:0px 0 0 200px;">Brian R Miller, priciple</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:200px 0 0 0">This email has been sent by an automated service</p> --PHP-alt-<?php echo $random_hash; ?>-- <?PHP $message = ob_get_clean(); mail($to, $subject, $message, $headers); ?> I'm using the php mail function and sending to Gmail accounts it shows "Unknown Sender" This is my header: Code: [Select] $headers = "From: XXXXX\r\nReply-To: XXXX@XXXXX.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; I read somewhere that removing the "\r" would work but no luck... any help would be awesome I'm using a simple form to grab an email address and send the person who signs up and automatic response. It was working for a while and now it's not. Not sure what happened. My hosting company told me to look into my headers. Can anyone help? Here is my code. Thanks, Code: [Select] <?php /* Set e-mail recipient */ $subject = "Sign Up"; $headers = "From: admin@xxx.com" . "\r\n" . "CC: admin@xxx.com"; /* Check all form inputs using check_input function */ $sign_up_email_address = check_input($_POST['sign_up_email_address'], "Please enter your email address."); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $sign_up_email_address)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $response_message = "Sample Message"; /* Send the message using mail() function */ mail($sign_up_email_address, $subject, $response_message, $headers); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <?php echo $myError; ?> Thank you, Hello, Something that's been really bugging me the last days is a problem in PHP, the mail(); function, so here goes. First, my script: Code: [Select] $to = "valid@hotmail.com"; $subject ="contact form"; $body = "Hello, you have been contacted"; $from = "$_POST['email']; $headers = 'From : valid@hotmail.com'."\r\n".'Reply-To: valid@hotmail.com'; if (mail($to, $subject, $body, $headers)) { echo "worked"; } else { echo "didn't work"; } I'm using Ubuntu linux and have set up an SMTP server like so: Code: [Select] sudo apt-get install postfix And configured it. I have also forwarded TCP port 25 to the server. Problem: I run the script and it echos 'worked', meaning that there was no error. However, I don't get a mail sent into my inbox. Thanks in advance, Drmota I've just setup an Apache server with a basic LAMP stack. We've decided to use Google Apps (gmail) as our mail server / host. So our ubuntu server is only serving up HTTP files. Because the server is not configured as a mail server, and we're using Gmail for our MX and mail servers, how do I go about using sending out emails via PHP on the Apache Box? I've tried installing Postfix, and configuring using this tutorial, and still a no go. http://www.blogternals.com/2009/04/30/postfix-google-apps-gmail-smtp-relay/ Any Ideas? i think because of my code used to send the mail, on my site, its appearing in the spam folder of most of my clients PLUS myself is their a way to eradicate this? correct headers? etc? Does any know how to set SMTP Mail Configuration using the gmail account? Hi PHP Developers, I am trying to integrate php mail script on my website mysmsmantra but getting error such as : Fatal error: Uncaught Error: Call to undefined method PEAR_Error::send() in /home/website/public_html/mysmsmantra.com/sendmail2.php:99 Stack trace: #0 {main} thrown in /home/website/public_html/mysmsmantra.com/sendmail2.php on line 99 I am using below code to send mail :
<?php
// your secret key
if ($_POST["g-recaptcha-response"]) {
$pcount=0; $from = "".$name." <".$_POST['email'].">"; $to = "info@yourdomain.com"; $subject = "Mail from mysmsmantra";
while (list($key,$val)=each($_POST))
if ($pcount > $gcount)
}
$headers2 = array ('From' =>$from2 ,
$smtp = Mail::factory('smtp',
Edited December 8, 2020 by mysmsmantra I am trying to integrate php mail script on my website Logon Utility but getting error such as :
<?php
// your secret key
if ($_POST["g-recaptcha-response"]) {
$pcount=0; $from = "".$name." <".$_POST['email'].">"; $to = "info@yourdomain.com"; $subject = "Mail from Logon Utility";
while (list($key,$val)=each($_POST))
if ($pcount > $gcount)
}
$headers2 = array ('From' =>$from2 ,
$smtp = Mail::factory('smtp',
Hi, Can someone please post very straight forward lines for sending email (no attachment nothing, just a subject and one line text in body) using google smtp (ssl://smtp.gmail.com) without any help of some classes like PHPmailer? Thanks, I'm getting the following error: Quote Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in (file path) I'm sure this error has been posted before, but I've searched and can't find a solution. I'm running XAMPP 1.7.3 with the Mercury/32 mail server v.4.72, which IS set to permit SMTP relaying of non-local mail. Is there anything I can change in php.ini, or anywhere else for that matter, to solve this? I'm tearing my hair out with this... If I can just get it to send out this email, my project is finished, but I've been wrestling with this mail() function for about 3 hours. Any help would be appreciated. |