Jump to content

Help ! How Do I Send Mail Using Smtp


bisihughes

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.