bisihughes Posted November 21, 2012 Share Posted November 21, 2012 Hi guys, Am having a little issue i cant seem to send email from my site - my hosting company said the ()mail function is disable due to spam and things. Anyways want i to send mail using smtp and have got no idea how to go about it. here is my html code <form id="contact-form" class="checkform" action="" target="http://www.mydomain.com/contact_send.php" method="post"> <div> <label for="name" class="req">NAME *</label> <input type="text" name="name" class="name" value="NAME *" onfocus="if (this.value == 'NAME *') {this.value = '';}" onblur="if (this.value == '') {this.value = 'NAME *';}"/></div> <div> <label for="email" class="req">EMAIL *</label> <input type="text" name="email" class="email" value="EMAIL *" onfocus="if (this.value == 'EMAIL *') {this.value = '';}" onblur="if (this.value == '') {this.value = 'EMAIL *';}"/></div> <div> <label for="subject">SUBJECT</label> <input type="text" name="subject" class="subject" value="SUBJECT" onfocus="if (this.value == 'SUBJECT') {this.value = '';}" onblur="if (this.value == '') {this.value = 'SUBJECT';}"/></div> <div> <label for="message" class="req">MESSAGE *</label> <textarea name="message" class="message" onfocus="if (this.value == 'MESSAGE *') {this.value = '';}" onblur="if (this.value == '') {this.value = 'MESSAGE *';}" rows="15" cols="50">MESSAGE *</textarea></div> <div><input class="submit" type="submit" value="Send" name="submit_form" /></div> <input type="hidden" name="fields" value="name,email,subject,message," /> <input type="hidden" name="sendto" value="xxxxxx@gmail.com" /> <input type="hidden" name="subject" value="Custom Subject" /> </form> and the contact.php code <?php define("WEBMASTER_EMAIL", $_POST['sendto']); if (WEBMASTER_EMAIL == '' || WEBMASTER_EMAIL == 'Testemail') { die('<span class="error_message">The recipient email is not correct</span>'); } define("EMAIL_SUBJECT", $_POST['subject']); if (EMAIL_SUBJECT == '' || EMAIL_SUBJECT == 'Subject') { define("EMAIL_SUBJECT",'Contact'); } $name = stripslashes($_POST['name']); $email = trim($_POST['email']); $message = stripslashes($_POST['message']); $custom = $_POST['fields']; $custom = substr($custom, 0, -1); $custom = explode(',', $custom); $message_addition = ''; foreach ($custom as $c) { if ($c !== 'name' && $c !== 'email' && $c !== 'message' && $c !== 'subject') { $message_addition .= '<b>'.$c.'</b>: '.$_POST[$c].'<br />'; } } if ($message_addition !== '') { $message = $message.'<br /><br />'.$message_addition; } $message = '<html><body>'.nl2br($message)."</body></html>"; $mail = mail(WEBMASTER_EMAIL, EMAIL_SUBJECT, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion() ."MIME-Version: 1.0\r\n" ."Content-Type: text/html; charset=utf-8"); if($mail) { echo '<span class="confirm_icon">Confirm</span><span class="confirm_message"><strong>Your message has been sent. Thank you!</strong></span>'; } else { echo '<span class="error_icon">Error</span><span class="error_message"><strong>Your message has not been send!</strong></span>'; } ?> i would like to use gmail not email account from the hosting company Any help will be appreciated Thanks Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/ Share on other sites More sharing options...
Muddy_Funster Posted November 21, 2012 Share Posted November 21, 2012 if you have access to PEAR then you can get a script from my blog that will do what you are after, You could also google phpMailer, I think it's been brought back out of mothballs and does a hell of a lot of good stuff for mailing with php. As far as I know gmail doesn't do SMTP, only Secure IMAP. I could be wrong though, never really looked into it in deapth. Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394046 Share on other sites More sharing options...
haku Posted November 21, 2012 Share Posted November 21, 2012 Gmail does allow SMTP. And PHPmailer works well, I've used it lots. Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394052 Share on other sites More sharing options...
bisihughes Posted November 21, 2012 Author Share Posted November 21, 2012 Thanks guys for the response - so how do i tweak the code to allow sending through smtp - as i am still learning. Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394095 Share on other sites More sharing options...
Muddy_Funster Posted November 21, 2012 Share Posted November 21, 2012 which code? If you want to use SMTP you will need to get (as in download) either the PEAR Net_SMTP class or the phpMailer library - your existing code will need to be rewritten to use one of these, it's not just a quick tweek to what you have. Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394099 Share on other sites More sharing options...
bisihughes Posted November 21, 2012 Author Share Posted November 21, 2012 which code? If you want to use SMTP you will need to get (as in download) either the PEAR Net_SMTP class or the phpMailer library - your existing code will need to be rewritten to use one of these, it's not just a quick tweek to what you have. Thanks. That's exactly what i mean - how to rewrite the code to allow smtp ? Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394104 Share on other sites More sharing options...
Muddy_Funster Posted November 21, 2012 Share Posted November 21, 2012 Well that depends on which of the PEAR/phpMailer options you are going to use - I would suggest phpMailer, as it's got some good documentation, and more people on here will have used it. If you opt for the PEAR route you would be best off just lifting the code from my blog and tweeking that to suit your needs as there is next to no practical documentation out there about how to code for it (at least there wasn't when I was trying). Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394120 Share on other sites More sharing options...
bisihughes Posted November 21, 2012 Author Share Posted November 21, 2012 Well that depends on which of the PEAR/phpMailer options you are going to use - I would suggest phpMailer, as it's got some good documentation, and more people on here will have used it. If you opt for the PEAR route you would be best off just lifting the code from my blog and tweeking that to suit your needs as there is next to no practical documentation out there about how to code for it (at least there wasn't when I was trying). Alright my man - thanks! Quote Link to comment https://forums.phpfreaks.com/topic/270978-help-how-do-i-send-mail-using-smtp/#findComment-1394189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.