Jump to content

PHP script to send a mail


getyourkarthick

Recommended Posts

I'm going to vote for this choice as being the likely problem -

..., or you could have an error in your code, ...

 

You haven't shown any code, so it is not possible to tell if what you are attempting is even valid.

 

Based on your other thread about SMTP Authentication, does your sending mail server require it? If it does, there's no way you will be able to send an email through your mail server until you use a php script that supports SMTP Authentication.

 

Edit: And frankly, you have at least two-three current threads about sending email. If you stick to a single thread for any particular problem, you will find that you will get a solution faster.

Link to comment
Share on other sites

<?php

session_start();

if ($_POST['Submit'] == 'Send')

{


$to = $_POST['toemail'];

$subject = $_POST['subject'];

$message = $_POST['message'];

$fromemail = $_POST['fromemail'];

$fromname = $_POST['fromname'];

$lt= '<';

$gt= '>';

$sp= ' ';

$from= 'From:';

$headers = $from.$fromname.$sp.$lt.$fromemail.$gt;

mail($to,$subject,$message,$headers);

header("Location: sendmail.php?msg= Mail Sent!");

exit();

}

?>

<html>

<head>

<title>Email </title>

</head>

<body bgcolor="#ffffcc">

<h2 align="center">

Email
</h2>

<h3 align="center">

Please do not misuse this script.
</h3><br>

<p style="margin-left:15px">

<form action="sendmail.php" method="POST">

<b>From Name:</b><br>

<input type="text" name="fromname" size="50"><br>

<br><b>From Email:</b><br>

<input type="text" name="fromemail" size="50"><br>

<br><b>To Email:</b><br>

<input type="text" name="toemail" size="50"><br>

<br><b>Subject:</b><br>

<input type="text" name="subject" size="74"><br>

<br><b>Your Message:</b><br>

<textarea name="message" rows="5" cols="50">

</textarea><br>

<input type="submit" name="Submit" value="Send">

<input type="reset" value="Reset">

</form>

</p>

<?php if (isset($_GET['msg'])) { echo "<font color=\"red\"><h3 align=\"center\"> $_GET[msg] </h3></font>"; } ?>

</body>

</html>

 

This is the code..

Link to comment
Share on other sites

Aside from the fact that you are allowing all the mail() parameters (to, subject, message, From: header) to come from the posted form data (spam bot scripts will love your script and get your mail server banned by all the major ISP's fairly quickly) you are setting the From: address to be the arbitraryly entered email address from the form (which is probably why you are likely triggering your mail server's SMTP Authentication requirement.)

 

You must set the From: address to be an email address hosted at the sending mail server. You would set the Reply-to: address to be the address the visitor entered.

Link to comment
Share on other sites

What kind of email address are you trying to send it to? Is it hosted on the same server? or is it hotmail gmail etc? If its not try adding something like this.

$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

 

I have configured my smtp server with gmail..What the above code will do..?

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.