PHP - Sendmail Function ??
Hi, my webhost has the mail() function disabled. However, my emails are hosted in the offices sever and can't use smtp due to the firewall blocking it. How do I setup sendmail instead of the mail(). I tried googling this but keep coming across to the mail() functions.
Similar TutorialsI am getting an error on a form which sends an email if the form is succesfull. I think there may ne an issue with the sendmail function. I am using a hosting company and not sure if sendmail is something that has to be enabled in the .ini file. Is there any way to check without getting the hosting company involved? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=359470.0 I wrote this code and I keep getting Parse error: syntax error, unexpected $end in the last line <?php $subject = 'Registration'; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $email = $_POST['email']; $mortgage = $_POST['mortgage']; $comments = $_POST['comments']; if($fname == ""){ echo 'Please fill out a First Name'; exit(); }elseif($lname == ""){ echo 'Please fill out a Last Name'; exit(); }elseif($address == ""){ echo 'Please fill out an Address'; exit(); }elseif($city == ""){ echo 'Please fill out a City'; exit(); }elseif($state == ""){ echo 'Please fill out a State'; exit(); }elseif($zip == ""){ echo 'Please fill out your Zip Code'; exit(); }elseif($phone == "") { echo 'Please fill out a Telephone Number'; exit(); }elseif($mortgage == "") { echo 'Please fill out a Mortgage Company'; exit(); }else{ $to = 'amphit@live.com'; $mailfrom = '$email'; $header = "from: $fname $lname <$mail_from>"; $detail = "First name - $fname <br> Last Name - $lname <br> Address - $address <br> City - $city <br> State - $state <br> Zip - $zip <br> Phone - $phone <br> Email - $email <br> Mortgage - $mortgage <br> Comments - $comments"; $send_mail=mail($to,$subject,$detail,$header); if($send_mail){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> Hi guys I'm seriously stressing hard about this. I seem to have written everything properly but my contact form just won't send an e-mail and update the status on my webpage. I fill out the details on my contact form and my status text stays on "Email is sending...". I'd REALLY REALLY appreciate any help you could toss my way. Thanks a ton! sendmail.php <?php $name = @trim(stripslashes($_POST['name'])); $from = @trim(stripslashes($_POST['email'])); $subject = @trim(stripslashes($_POST['subject'])); $message = @trim(stripslashes($_POST['message'])); $to = 'myemail@gmail.com';//replace with your email $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; $headers[] = "From: {$name} <{$from}>"; $headers[] = "Reply-To: <{$from}>"; $headers[] = "Subject: {$subject}"; $headers[] = "X-Mailer: PHP/".phpversion(); mail($to, $subject, $message, $headers); die(); ?> main.js //Contact Form var form = $('#contact-form'); form.submit(function(event){ event.preventDefault(); var form_status = $('.form-status'); $.ajax({ url: $(this).attr('action'), beforeSend: function(){ form_status.find('.form-status-content').html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn(); } }).done(function(data){ form_status.find('.form-status-content').html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(3000).fadeOut(); }); }); contact.html <form class="form-horizontal" id="contact-form" role="form"> <div class="form-group form-status"> <div class="col-sm-offset-2 col-sm-6"> <div class="form-status-content"> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="text" name="name" class="form-control input-lg" placeholder="Name" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="email" name="email" class="form-control input-lg" placeholder="Email" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <input type="text" name="subject" class="form-control input-lg" placeholder="Subject" required="required"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <textarea name="message" rows="6" class="form-control input-lg" placeholder="Message" required="required"> </textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <button type="submit" class="btn btn-lg btn-transparent">Submit</button> </div> </div> </form> Edited February 27, 2020 by g0dtier Hello, I am using the Pear Mail and Mail_Mime packages to send SMTP authenticated HTML formatted emails. I was successfully sending emails when I started getting the following error: sendmail: 451 Internal Error I check out the sendmail logs at /var/log/mail.log but that only says the same thing. I am running Linux-Ubuntu and sending emails from an address on a remote server (godaddy hosted). The interesting thing is that this exact same code will run to completion and fail. Any thoughts? Anyone with Pear Mail experience, is there any way to end the SMTP session, maybe that is the problem. I also think an issue might be that the server thinks my IP is sending too many emails, any way to provision against that? Thanks for any insight and please let me know if other information might be helpful to debug this. Hi I am having a problem with the code below I am using to send a simple php email form. I am not that advanced with php but I want to add a drop down menu to a form I created and not sure how to get get the message (warning not completed) in the field - if(empty($visitortitle)) { - to accept or not to accept? This is the code in the form: <td align="left"><select name="visitortitle"> <option>Please Select</option> <option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option> <option>Dr</option> </select> This is the code I have got in the sendemail: if(empty($visitortitle)) { echo "<h2><br /><br /><br /><br />Please hit the back button and enter the title drop down box correctly<br />before you try submitting the form again.</h2>\n"; die ( '<a href="forum.html">click here go back and try again</a>' ); } How can I get this code to recognise that a <option></option> has been selected? Any help would be appreciated. Thanks Gary Here is my sendmail.php code: <?php //capture form data in name/value structure //ie. fName = "Pouya" $fNameVar = $_POST['fName']; $lNameVar = $_POST['lName']; $emailVar = $_POST['email']; $commentVar = $_POST['comment']; $telVar = $_POST['tel']; //echo "First Name is {$fNameVar}, last name is {$lNameVar}, email is {$emailVar} and comment is {$commentVar}"; // The e-mail function requires 3 types of info // A. Destination e-mail // B. Subject line // C. Body of your message // D. E-mail of sender mail("puya.turkiyan@gmail.com", "Message from my New Media Sources", $commentVar, "From:$emailVar"); //echo "Thank you $fNameVar" header("Location:thankyou.php"); ?> In the mail section I can only send 2 variables. As soon as I add the third it doesn't even send anything to my e-mail. Please help, its driving me crazy. Here is my table page: <?php include "header.html"; ?> <div id="templatemo_menu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="about.php">About Us</a></li> <li><a href="services.php">Services</a></li> <li><a href="gallery.php">Gallery</a></li> <li><a href="#">Blog</a></li> <li><a href="contact.php" class="current">Contact Us</a></li> </ul> </div> <!-- end of templatemo_menu --> <?php include "socialmedia.html"; ?> <div class="cleaner"></div> </div> <div class="cleaner"></div> </div> <!-- end of header --> </div> <!-- end of header_wrapper --> <div id="templatemo_content_wrapper"> <div id="templatemo_content"> <h1>Contact Information</h1> <p>Here are a few ways to get a hold of us. The best way would be e-mail or phone but you can also use other methods such as <a href="http://www.twitter.com/pehlavoon"><img src="images/twitter-1.png" alt="twitter" width="30" height="30"/> </a> or <a href="http://www.facebook.com/puya.turkiyan"><img src="images/facebook-1.png" alt="facebook" width="30" height="30"/></a> to contact us.</p> <div class="cleaner_h50"></div> <div class="two_column float_l"> <div id="contact_form"> <h2>Contact Form</h2> <fieldset> <legend>Contact me</legend> <form action="sendmail.php" method="post"> <ul> <li><label for="fName">First Name: </label> <input type="text" name="fName" value="" id="fName" /></li> <li><label for="lName">Last Name: </label> <input type="text" name="lName" value="" id="lName" /></li> <li><label for="email">E-mail: </label> <input type="text" name="email" value="" id="email" /></li> <li><label for="tel">Phone number: </label> <input type="text" name="tel" value="" id="tel" /></li> <li><label for="comment">comment: </label> <textarea cols="5" rows="5" name="comment" id="comment"></textarea></li> <li><input type="submit" value="Send" /></li> </ul> </form> </fieldset> </div> </div> <div class="two_column float_r"> <h6>Contact our development team:</h6> Located in Vancouver Canada<br /> <strong>Email:</strong> <a href="mailto:puya.turkiyan@gmail.com">puya.turkiyan@gmail.com</a> <p><strong>Phone:</strong> 1+778-991-7892</p> <div class="cleaner_h60"></div> <h6>Contact our Account manager</h6> Located in Downtown Vancouver Canada<br /> <strong>Email:</strong> <a href="mailto:richardboulier@gmail.com">richardboulier@gmail.com</a> <p><strong>Phone:</strong> 1+778-230-1084</p> </div> <div class="cleaner"></div> </div> <!-- end of content --> </div> <!-- end of content_wrapper --> <?php include "footer.html"; ?> Take a look and see if you can help me. Had the following code working for months and now its not working anymore??? I dont't think the code is the correct way to do it but it did work, Can someone please look at it or give me the correct code. All I am trying to do is take the data from the form and email it to an email address and cc the user that filled out the form. I would like to add a bcc in the future. Here is my current code <?php $email = $_POST['EMAIL']; $mailto = "user@domain.com, user@domain.org"; $mailhead = "FROM: LOI<user@domain.org>"."\r\n"; $mailhead .= "Reply-To: user@domain.org"."\r\n"; $mailhead .= "CC: ".$email; $mailbody = "Values submitted from LOI:\n"; while (list($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; } mail($mailto, $mailsubj, $mailbody, $mailhead); header("LOCATION: letter.html"); ?> (my file structure is the following. inquiry.html has a form and the submit button goes to letter.php(code above) then it directs to letter.html) Thanks Trevor This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=313491.0 I Have the following issue and I spend my whole day looking for it. I have a database with a simple admin where I add/delete values. The database structure is the following: id, zip, email The database is called zipdatabase Here is the mailing part: Code: [Select] //headers $headers = "From: <$Email>"; $headers .= "\r\nBcc: <$Bcc>\r\n\r\n"; // send email $success = mail($EmailTo, $Subject, $Body, $headers);The variable $Bcc must come from the database. I am really ignorant so I only got to a point on how to echo the results I need (and this works): Code: [Select] $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "{$r['email']}, "; } ?> For a zip I get more than one result so when I tried using this Code: [Select] $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $Bcc = "{$r['email']}, "; } echo "Bcc" ?> It only gives me one result. What I noticed is I have 2 issues: - I can't extract the BCC from the database - I don't know how to add more email addresses to the bcc field, I only managed to add more addresses to the $Emailto like: Code: [Select] $EmailTo = "address1@domain.com, address2@domain.com"; $Bcc = "address3@domain.com"; All these variables are defined by a webform and it works flawlessly except the database problem: Code: [Select] $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $ZIP = Trim(stripslashes($_POST['ZIP'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "ZIP: "; $Body .= $ZIP; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; Sorry for my ignorance and hope someone here can help. The webform works perfectly except the bcc from the database part. I've got PHP setup on Ubuntu with MySQL. I've got sendmail installed but for some reason I can't get mail() to work. Does anyone have good guidelines for getting this setup properly? First off, I am new to PHP, and want to learn it, but it seems very complicated. Where do I begin? I found a script online for a contact form and I am having trouble making it work for my needs. I wanted to include a phone number field in the email message. This is what I have so far for the PHP, but it does not include the phone field in the body of the message. Everything else works fine. Apologize in advance if this message has been posted many times before. <?php $post = (!empty($_POST)) ? true : false; if($post) { include 'functions.php'; $name = stripslashes($_POST['contactname']); $email = trim($_POST['email']); $subject = "New Message from your website"; $message = stripslashes($_POST['message']); $phone = stripslashes($_POST['phone']); $error = ''; // Check name if(!$name) { $error .= 'Please enter your name.<br />'; } // Check email if(!$email) { $error .= 'Please enter an e-mail address.<br />'; } if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.<br />'; } // Check message (length) if(!$message || strlen($message) < 15) { $error .= "Please enter your message. It should have at least 15 characters.<br />"; } if(!$error) { $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail) { echo 'OK'; } } else { echo '<div class="notification_error">'.$error.'</div>'; } } ?> This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 Hello all, I have some piece of code that is nested like this $variable = 'This is a global argument'; function parentFunction($variable) { function childFunction() { echo 'Argument of the parent function is '.$GLOBALS['variable']; } childFunction(); } parentFunction(5); What I want to know is - Is there a way to access a variable from the parent function without passing arguments to the child function? (Something like how classes have parent::?). I don't want to use $GLOBALS because it might cause some variable collision, and I didn't want to pass arguments because incase I decide to change the arguments in the parent function I'd have to do it in the child function aswell. From my searching around in the Internet it seems like this is not possible, but if theres a slight chance that there might be something out there, i'm willing to give it a shot . Thanks in advance I have this function completely written in my class file that I am working on. The point to this function is to be able to check the login of a user or administrator for either of the control panels associated with my site. It will check the session intime as well as the page / module referenced. Once it passes all those checks, it will check and ensure the emailaddress/password stored in the current session still holds true and the account is still active... if the account is still active it will update the lastActivity as well as update all of the session variables with what is currently in the database. What I am looking for is basically a look at the function, see if it looks good.. If there is any part to it that could create security holes for the site just off the login function itself... Usage: $q->validUser($_SESSION['user'], $_mod); <?php function validUser($sess, $p) { if ($sess['inTime'] == '' && $p != 'login' && $p != 'logout') { session_destroy(); $login = '0'; $_int = ''; return $login; } else if ($sess['inTime'] < time()-3600 && $p != 'login') { $sess['inTime'] = ''; session_destroy(); $this->check_login($sess, $p); } else { $this->user = $sess['emailAddress']; $this->pass = $sess['password']; $login = $this->sql_query("SELECT * FROM users WHERE emailAddress = '".$this->user."' AND password = '".$this->pass."' AND status = '1' LIMIT '1'"); if ($login = $this->sql_numrows($login) < 1) { $sess['inTime'] == ''; session_destroy(); $login = '0'; } else { // logged in, lets update the database for last_activity AND the session. $this->sql_query("UDATE users SET lastActivity = '".now()."' WHERE emailAddress = '".$this->user."'"); $login = $this->sql_query("SELECT * FROM users WHERE emailAddress = '".$this->user."' AND password = '".$this->pass."' AND status = '1' LIMIT '1'"); $login = mysql_fetch_assoc($login); foreach ($login as $key => $value) { $sess[$key] = $value; } $sess['inTime'] = time(); $login = '1'; } return $login; } } ?> That is the main function, sql_query and sql_numrows is: <?php function sql_query($query = "", $transaction = FALSE) { unset($this->query_result); if ($query != "") { $this->num_queries++; if ($transation == BEGIN_TRANSACTION && !$this->in_transation) { $result = mysql_query("BEGIN", $this->db_connect_id); if (!$result) { return false; } $this->in_transaction = TRUE; } $this->query_result = mysql_query($query, $this->db_connect_id); } else { if ($transaction == END_TRANSACTION && $this->in_transaction ) { $result = mysql_query("COMMIT", $this->db_connect_id); } } if ($this->query_result) { unset($this->row[$this->query_result]); unset($this->rowset[$this->query_result]); if ($transaction == END_TRANSACTION && $this->in_transaction ) { $this->in_transaction = FALSE; if (!mysql_query("COMMIT", $this->db_connect_id)) { mysql_query("ROLLBACK", $this->db_connect_id); return false; } } return $this->query_result; } else { if ($this->in_transaction ) { mysql_query("ROLLBACK", $this->db_connect_id); $this->in_transaction = FALSE; } return false; } } function sql_numrows($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } return ($query_id) ? mysql_num_rows($query_id) : false; } ?> Any insight that can help to benefit these functions would be appreciated. Question 1) Is the only and proper way to call a parent function "parent::function()"? Are there other/better ways from within a child function? Question 2) What are the deciding factors for when to make a function or attribute static? How do you make that decision? Assuming 5.3... Thanks. I need to call usort from a class function, and I'm puzzled about how to define the comparison function. I've tried to define the comparison function in the same class, but I can't get usort to call it. I found one hint that it will work if I make the comparison function static, but I tried that, and it didn't work for me. If I define the comparison function outside the class, it won't have access to object properties that it needs to operate. The only solution I can think of is to define the comparison function outside the class and put the object properties it needs in globals. Is there a cleaner way to do this? I want to define a function instead of repeating query in all my php pages. I call a function by passing an $id value and from that function i have to get all the info related to that id, like name, description and uom.
I am trying to do this, but i dont know how to get these values seperately.
here is my function
function items($item_id) { $details = array(); $result = mysql_query("select item_id, name, uom, description from items where item_id=".$item_id."") or die (mysql_error()); while($row = mysql_fetch_array($result)) { $details[] = array((stripslashes($row['name'])), (stripslashes($row['uom'])), (stripslashes($row['description']))); } return $details; }and i call my function like this $info = items($id);Can somebody guide me in this When I put this chunk of code into it's own function: function fetch_all ($dbc, $query) { include ('knuffix_list_func.php'); pagination_start ($dbc, $query); $offset = $pag_array[0]; $rows_per_page = $pag_array[1]; $query = $query . " LIMIT $offset, $rows_per_page"; echo "test query: " . $query; knuffix_list ($query, $dbc); pagination_end ($pag_array); } And when I echo out the query as you can see in the example, then I notice that the variables $offset and $rows_per_page never get appended. I set the variable $pag_array to a global inside the function pagination_start(). It usually works when I DON'T wrap a function around this chunk of code, but if I do wrap a function around everything then the global suddenly won't work anymore. Btw, this also won't work if I wrap a function around the function DECLARATIONS. Any ideas, how I could make it work? Hi all, I want to call a javascript function from a php function like this: public function Buscar() { $HoraInicio = $_POST['edtHoraInicio']; $HoraFin = $_POST['edtHoraFin']; $FechaInicio = $_POST['edtFec1']; $FechaFin = $_POST['edtFec2']; $FechaMax = $FechaFin." ".$HoraFin.":00"; $FechaMin = $FechaInicio." ".$HoraInicio.":00"; $_GET["FechaMax"] = $FechaMax; $_GET["FechaMin"] = $FechaMin; echo $FechaMin; echo "<script language=javascript>alert('Hi.')</script>"; } but the function Buscar never show the alert but shows the $FechaMin I hopu u guys can help me out with this probem Thanks, Siddhartha |