PHP - Email Address Not Showing
Ok I am very new to php so please excuse my lack of knowledge.
I have a simple contact form that I have placed onto one of my sites. The form works correctly in that it get sent to the correct address without any problems. The issue I am having is with the 'From' header. It will not show the senders email address as I would like. Instead it seems to be showing the server address. I have been 'playing' with the code for 2 days now and I still cannot get it to work. Any suggestions would be greatfully received. Regards. Code: [Select] <?php if(!$_POST) exit; $email = $_POST['Email']; $name = $_POST['Name']; $telephone = $_POST['Telephone']; $comments = $_POST['Comments']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('Name','Email','Telephone','Comments'); $required = array('Name','Email','Telephone','Comments'); $your_email = "**********************"; $email_name = "Message From your Website:"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'Name' && $key != 'Comments' && $key != 'Telephone') { if( empty($_POST[$value]) ) { echo 'Please go back and complete all fields, thank you.'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_name,$email_content)) { echo 'Thank you for your message, we will be in touch shortly'; } else { echo 'ERROR!'; } } $headers = "From: $email\r\n"."Reply-To: $email\r\n".'X-Mailer: PHP/' . phpversion(); @mail($your_email,$name,$email,$telephone,$comments,$headers); ?> Similar Tutorialsi wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers I have a form with PHP validation and also a mysqli query checking for duplicates in the database for mailing address and email address in mysql.
It works fine but the customers are adding spaces in the mailing address for example 111 mailing address A V E, 1 1 1 ma iling address A V E etc. and my sql query doesn't see that as an address that's a duplicate.
Their alslo adding email address like my@emailaddress.com and m.y@emailaddress.com, m.y.2@emailaddress.com etc to bypass that comparision also.
Is there anyway to stop this from happening?
Hello, I am working with a SMTP class to send an email. It's all working perfectly fine, but when the email is received (sent from the online form), and I open my email and click reply, there are two email addresses. The correct one (which I entered when I sent the email), and my ftp username for the site?? I've got three files that could effect this, but I was unable to locate any problems: mailer.php ( smtp send mail class) mail.php ( submission data: title, subject, etc. ) contact_form.php ( form for submission ) I am only including the file which I think is applicable (mail.php), but let me know if you would also like to see the mailer.php class. Current output: reply-to ftpusername@domainname.com, correct_from_email@fromemail.com mail.php: <?php set_time_limit(120); function sendHTMLmail($from, $to, $subject, $message) { $message = wordwrap($message, 70); // 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 .= "From: $from\r\n"; // Mail it mail($to, $subject, $message, $headers); } function sendHTMLmail2($fromid, $to, $subject, $message) { echo $fromid; echo $to; echo $subject; echo $message; include_once("mailer.php"); $mail = new PHPMailer(); $mail->IsMail(); // SMTP servers $mail->Host = "localhost"; $mail->From = $fromid; $mail->FromName = $fromid; $mail->IsHTML(true); $mail->AddAddress($to, $to); $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = "Please enable HTML to read this"; $mail->Send(); exit; } function isValidEmail($email) { return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email); } class smtp_mail { var $host; var $port = 25; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $charset = "utf-8"; var $in; var $from_r; //mail format 0=normal 1=html var $mailformat = 0; function smtp_mail($host, $port, $user, $pass, $debug = false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket) { $this->result_str = "Create socket:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->conn = socket_connect($this->socket, $this->host, $this->port); if ($this->conn) { $this->result_str = "Create SOCKET Connect:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->result_str = "Server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if ($this->debug) { echo $str . "<p>\r\n"; } } function send($from, $to, $subject, $body) { if ($from == "" || $to == "") { exit("type mail address please"); } if ($subject == "") $sebject = "none title"; if ($body == "") $body = "none content"; $All = "From:$from;\r\n"; $All .= "To:$to;\r\n"; $All .= "Subject:$subject;\r\n"; if ($this->mailformat == 1) { $All .= "Content-Type:text/html;\r\n"; } else { $All .= "Content-Type:text/plain;\r\n"; } $All .= "Charset:" . $this->charset . ";\r\n\r\n"; $All .= " " . $body; $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user . "\r\n"; $this->docommand(); $this->in = $this->pass . "\r\n"; $this->docommand(); if (!eregi("235", $this->result_str)) { $this->result_str = "smtp auth faild"; $this->debug_show($this->result_str); return 0; } $this->in = "MAIL FROM: $from\r\n"; $this->docommand(); $this->in = "RCPT TO: $to\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All . "\r\n.\r\n"; $this->docommand(); if (!eregi("250", $this->result_str)) { $this->result_str = "Send mail faild!"; $this->debug_show($this->result_str); return 0; } $this->in = "QUIT\r\n"; $this->docommand(); socket_close($this->socket); return 1; } function docommand() { socket_write($this->socket, $this->in, strlen($this->in)); $this->debug_show("Client command:" . $this->in); $this->result_str = "server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } } ?> Hi, n0obie here. I'm trying to identify where my customers are coming from via emails I've sent/received. However, many email providers (namely Gmail) have circumvented this by disallowing IP address geolocation/image caching. I use this code to open the contents of my Menu Links inside my <div id="main"> so I do not need to reload the whole page each time: I'm using this php code and would like to know if there is a way to hide the email? Code: [Select] echo "Email: <span style='color:#00F'><a href='mailto:".$result['email']."?subject=".$result['title']."'>".$result['email']."</span></a>"; I need to replace everything after the @, but before the . with X's on a page. I can remove the email with this Code: [Select] $result = substr($email, 0, stripos($email, "@") ); but now how do I go about replacing the @domain.com with X's? Example: Suppose the email address is test@test.com I need the email address to show on the page like this test@xxx.com Thanks in advance i have the following problem i have a mail id displayed on the site. on clicking the link the email address should get saved to the outlook express contacts. all i have been doing is reading through but did not find any revelance to implement any help of any sort will be appreciated thanks Hi, im working on a Stripe API, trying to extract the email address from the payment customer details. How do I get the email from the following string "customer_details":{"email":"emailaddress@gmail.com","tax_exempt":"none","tax_ids":[]}
I have been using the following which returns the entire string: Would like to only return the email address, but I am unsure how to achieve this (sorry PHP newbie here) Can someone explain whats wrong with this code: if ($this->email != $this->confemail){ $this->errors[] = 'The email addresses you entered did not match!'; } I'm trying to make a "Confirm email" field by comparing "email" with "confemail" and if they are not the same you should get this message 'The email addresses you entered did not match!'. But instead i get this no matter what i type into the fields? Hi guys, Trying to ge this to work: function checkEmail($useremail) { if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $useremail)) { return false; $error = '<div id="blackText"><p>Sorry! Please check your email address and try again!<p><p><a href="forumsSignUp.php">Back</a></p></div>'; } return true; //PASSWORD AND OTHER VALIDATION STUFF, blah blah blah } But its just not. Everything works fine if I remove this though. Can anyone suggest an alternative to email address validation? Thanks! Hi, I'm trying to make an order form in php, basically I want the email to be sent to different email address in different email format, but I'm stuck with the code, can anyone help me with this, please? I've been trying to figure it out for a couple of days but I still can't solve it, my background is not in programming so, I think this must be really easy for programmers, but it's been causing me a headache. Below is the code that I've been stuck. <?PHP /* SUBJECT AND EMAIL VARIABLE */ $emailSubject = ' crystal ashley order form '; $webMaster = 'tjoengkikitjahyadi@gmail.com, james.k.tj@gmail.com '; /* gathering data variable */ $emailField = $_POST['email'] ; $recipientField = $_POST['recipient'] ; $nameField = $_POST['name'] ; $phoneField = $_POST['phone'] ; $codeField = $_POST['code'] ; $quantityField = $_POST['quantity'] ; $hearField = $_POST['hear'] ; $classField = $_POST['class'] ; $commentsField = $_POST['comments'] ; $body = <<<EOD <br><hr><br> Email : $email <br> Recipient : $recipient <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); Email : $email <br> Name : $name <br> Phone : $phone <br> Code : $code <br> Code : $code2 <br> Hear from : $hear <br> Interested in : $class <br> Comments : $comments <br> <br> EOD; $headers = "From : $email\r\n"; $headers = "To : $recipient\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*results rendered as html*/ $theResults = <<<EOD <html> <head> <title>Real Yoga Enquiry Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! Your email will be answered very soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> I'm trying to add an email validation into the code so that it pops up with a similar message as the others if you don't use the @ or .com in your email address and it just ignores it and keeps sending the email anyways no matter what i put into the email field. here is the php i have for it i'm sure it's something really simple but i am not as familiar with php as i would like to be...
When i try and test this to make sure it works it only gives me the message that my email has been sent and i want it to not send if the email address doesn't have the @ sign or the .com or whatever kind of website it's from. I bolded the code that is not working the way i want it too.
<?php
if ($_POST['submit']) { Hello - I am very new to PHP. I have a simple form that uses gmail SMTP. The form works, but the sender always comes across as the email address from the gmail SMTP account. We need the sender to be the email address filled in on the form.
Here is the form:
Here is the PHP to send the form: <?php
$headers = array(
$smtp = Mail::factory('smtp', array(
if (PEAR::isError($mail)) { ?> How can I get the email to come from the address that's filled in on the form? I would be very grateful for any help...thank you so much!! So this is the code prior to trying to add a hyperlink echo "<p>Name: " . $item["first_name"] . " " . $item["last_name"] . "<br> Email: " . $item ["email"] . "</p>"; I thought that putting the <a href around the $item['email'] would make the email address a hyperlink but it does not ... it skips the email addresses completely and hyperlinks the names because all fields are $item. echo "<p>Name: " . $item["first_name"] . " " . $item["last_name"] . "<br> Email: " . "<a href=\"mailto: {$item ["email"]} \">" . "</p>"; Thank you for any assistance. I have a function that is supposed to find the email address of the user that's logged in my application. going by their ID:
function getUserEmail($userID){ $sqll="SELECT id,email FROM users WHERE id='".$userID."'"; $result1=mysql_query($sqll); $row11=mysql_fetch_assoc($result1); $processor=$row11["email"]; return $processor; }What I'm trying to do is incorporate that into sending a simple email to the person that's logged in after they submit a file. But the email is not being sent and I'm getting this message: Warning: mail() expects parameter 1 to be string, array given Here is what I have for sending the email : $sendto = getUserInfo($_REQUEST[1][email]); $subject = "File recieved"; $message = "Hello " . getUser($_REQUEST["user"]) . ". you successfully submitted: $title"; mail($sendto, $subject, $message);How do I extract just the email address to prevent giving the array? I am having trouble figuring out the right keywords to search for this, but what would I need to research if I want a user to send an email to a specific address (i.e. support@domain.com) and to have it create a new MySQL database entry, sort of like a help desk would generate? Hi folks, I just found this group and joined up! I have encountered a problem that I am not sure how to resolve, and I hope someone can assist. I run this query against my MySQL database: mysql_select_db($database_commdb, $commdb); $query_rsEmailAddress = "SELECT admin_email FROM tbl_admins WHERE admin_id = 1"; $rsEmailAddress = mysql_query($query_rsEmailAddress, $commdb) or die(mysql_error()); $row_rsEmailAddress = mysql_fetch_assoc($rsEmailAddress); $totalRows_rsEmailAddress = mysql_num_rows($rsEmailAddress); ...and want to use the result to populate the "mail to" field for my response form. (I'm doing this to avoid having my email address posted in a page to be skimmed.) I presently use this: $to = rsEmailAddress['admin_email']; I do some empty fields checking before submitting the form. However, when I click on submit, my form, tells me I have empty fields and will not process when there are NO empty fields. HOWEVER, if I hard-code my email address in the variable "$to" all is well, the form processes correctly, I get the email, etc... So I suspect the problem lies somewhere in the way I have constructed the $to variable. I have scratched my head till I am going bald(er) and my scalp is bleeding!!! HELP!! Please!! I want to make the form so only people with a specific email address can sign up to the site. So for example their ending email address was.... @something.apple.biz.com .. but to be accepted into the site, the email HAS to end with apple.biz.com. How could you validate it so it matches something specific like this. Here is my code at the moment which just checks that their is at least one . after the @ for it to be an acceptable email. If anyone could say what else to add to do this would be great if($email != '' && $register){ $emailcheck = explode("@", $email); $sql = "SELECT email FROM member WHERE email='$email'"; $query = mysql_query($sql); $emails = mysql_num_rows($query); if($emails != 0 ){ $alert .= '<p class="alert" style="clear:both;">That email address has already been registered</p>'; $register = false; }elseif(count($emailcheck) != 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; }elseif(count($emailcheck) == 2){ $emailchecktwo = explode(".", $emailcheck[1]); if(count($emailchecktwo) < 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; } } } Hi I have a simply working SMTP form, however I need this to send to a yahoo.com email address, what can I add to achieve this? SmtpConfig.php ============== <?php //Server Address $SmtpServer="91.186.30.25"; $SmtpPort="25"; //default $SmtpUser="things@wilsoncarandvanrental.co.uk"; $SmtpPass="things123"; ?> SmtpClass.php ============= <?php class SMTPClient { // A function for Setting up SMTP function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body) { $this->SmtpServer = $SmtpServer; $this->SmtpUser = base64_encode ($SmtpUser); $this->SmtpPass = base64_encode ($SmtpPass); $this->from = $from; $this->to = $to; $this->subject = $subject; $this->body = $body; //Setting Default port Value if ($SmtpPort == "") { $this->PortSMTP = 25; } else { $this->PortSMTP = $SmtpPort; } } //Sending the Mail function SendMail () { if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) { fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n"); $talk["hello"] = fgets ( $SMTPIN, 1024 ); fputs($SMTPIN, "auth login\r\n"); $talk["res"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpUser."\r\n"); $talk["user"]=fgets($SMTPIN,1024); fputs($SMTPIN, $this->SmtpPass."\r\n"); $talk["pass"]=fgets($SMTPIN,256); fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n"); $talk["From"] = fgets ( $SMTPIN, 1024 ); fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n"); $talk["To"] = fgets ($SMTPIN, 1024); fputs($SMTPIN, "DATA\r\n"); $talk["data"]=fgets( $SMTPIN,1024 ); fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n"); $talk["send"]=fgets($SMTPIN,256); //CLOSE CONNECTION AND EXIT ... fputs ($SMTPIN, "QUIT\r\n"); fclose($SMTPIN); // } return $talk; } } ?> mail.php ======== <?php //Include Class And Config include('SmtpConfig.php'); include('SmtpClass.php'); //Check the Request Method if($_SERVER["REQUEST_METHOD"] == "POST") { $to = $_POST['to']; $from = $_POST['from']; $subject = $_POST['sub']; $body = $_POST['message']; // Send the mail Using the class $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); $SMTPChat = $SMTPMail->SendMail(); } // After Exit, show the form ?> <form method="post" action=""> To:<input type="text" name="to" /> From :<input type='text' name="from" /> Subject :<input type='text' name="sub" /> Message :<textarea name="message"></textarea> <input type="submit" value=" Send " /> </form> Probably quite straight form, but of course I don#t know how :0) Much appreciated. |