• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

ASPMail in PHP?

http://support.persits.com/email/sendmail.asp

Is there such another software like the above but written in PHP instead of ASP?
I love the software but unfortunately I cannot use it on my webserver because it doesn't support ASP.
0
Donkadelics
Asked:
Donkadelics
  • 7
  • 3
1 Solution
 
SunilDVRCommented:
It would be comparatively simple to write your own, for sending mail at least.

I've not had a chance to test this right now, but a simple example would be something like this, using one page for an html form (email.html) and another with a PHP script on it to send it (confirmation.php):

#####################################################################
~~~~~~~~ email.html ~~~~~~~~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail Demo</title>
</head>

<body>
 <form name="form1" method="post" action="confirmation.php">
   <p>To:
       <input name="email" type="text" id="email">
</p>
<p>CC:
       <input name="cc" type="text" id="cc">
</p>

   <p>  Subject:
     <input name="subject" type="text" id="subject">
   </p>
   <p>Message:<br>
     <textarea name="content" cols="100" rows="15" id="content"></textarea>
   </p>
   <p>
     <input name="submit" type="submit" id="submit" value="Send">
   </p>
 </form>
</body>
</html>

~~~~~~~~ confirmation.php ~~~~~~~~


<?php
   // Get the variable names
   $email=$_POST['email'];
   $cc=$_POST['cc'];
   $subject=$_POST['subject'];
   $content=$_POST['content'];
   

   $headers= 'From: somewebserver@somedomain.com\r\n"
                                  .'CC:".$cc."';

   mail($email, $subject, $content, $headers);

?>

<html>
<head><title>Sent</title>
<body>
<h3>Your mail has been sent</h3>
</body>
</html

#####################################################################

That code is from the top of my head, and as I said is untested. It uses the PHP "mail" function, which is documented here: http://uk2.php.net/manual/en/ref.mail.php

It assumes that your web host has configured PHP to point to a mail-sending program on the webserver, which is likely.

It is nowhere near as pretty as it could be; additional headers can be added by adding "\r\n" after the "CC" bit (such as Reply-Address: and so on).

Finally, there is no error checking or any form of refinement in that. A *lot* could be done to improve it in these areas, but that is, I believe, as simple as it gets for what you're wishing to do. It should give you a decent starting point to work from.

Hope that helps,

Sunil
0
 
SunilDVRCommented:
Ok, having just played around a little more, I have noticed a few errors in my code. Firstly, I mucked up the quotes, and secondly, the CC function doesn't work as intended. A very simple version, without the CC or any other headers, works perfectly. The code for that is as follows:

#####################################################################
~~~~~~~~ email.html ~~~~~~~~
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail Demo</title>
</head>

<body>
 <form name="form1" method="post" action="confirmation.php">
   <p>To:
       <input name="email" type="text" id="email">
</p>
   <p>  Subject:
     <input name="subject" type="text" id="subject">
   </p>
   <p>Message:<br>
     <textarea name="content" cols="100" rows="15"></textarea>
   </p>
   <p>
     <input name="submit" type="submit" id="submit" value="Send">
   </p>
 </form>
</body>
</html>


~~~~~~~~ confirmation.php ~~~~~~~~

<?php
   // Get the variable names
   $email=$_POST['email'];
   $subject=$_POST['subject'];
   $content=$_POST['content'];

   $headers= "From: somewebserver@somedomain.com\r\n "
   mail($email, $subject, $content, $headers);

?>

<html>
<head><title>Sent</title>
<body>
<h3>Your mail has been sent</h3>
</body>
</html

#####################################################################

If I can get the "headers" thing working I'll update this... it is probably something stupid in terms of the formatting I missed.

Sunil
0
 
SunilDVRCommented:
Ooops. I'm a bit tired! The line

$headers= "From: somewebserver@somedomain.com\r\n "

should read

$headers= "From: somewebserver@somedomain.com\r\n ";

Note the missing semi-colon on the end!

Sunil
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SunilDVRCommented:
I've done a bit of digging around, and

http://phpmailer.sourceforge.net/

that might be useful, if you want to get more complex (without driving yourself nuts with MIME headers and so on).

Sunil
0
 
SunilDVRCommented:
And in my 2nd example, note also the missing ">" in the "</html>".... not my night.

I hope this has helped somewhat...

Sunil
0
 
SunilDVRCommented:
A quick, and blazingly obvious point - if you put multiple email addresses in the "To:" field, seperated by commas, it will work fine. I'm not sure off the top of my head whether this will hit some practical limit, or if it is not recommended - it is likely to be the latter, given that there is a "CC" header in the spec.

Sunil
0
 
DonkadelicsAuthor Commented:
Can you write one with the CC and the Attachment?
0
 
DonkadelicsAuthor Commented:
I'm using Advance SMTP Server as my SMTP to send mail.
0
 
SunilDVRCommented:
Firstly, I posted that to help you get started... I am a student in the middle of end-of-year exams at the moment, and with 2 coming up on Friday and Saturday I really don't have time right now to come up with a complete solution. Also, extending the basic example from what I've shown would not be particularly difficult at least for the CC: field (as I pointed out, multiple addresses in the To: field actually works).

MIME content types (which you would need if you want to start throwing attachments about) are a pain in the neck to work on, as a simple syntax error can cause immense problems, and I'm afraid I simply don't have the time at present to do all the reading and coding required. If I did I would probably be working in an IT department somewhere and being paid for it!

I've given you a sensible starting point, if you check the php.net documentation of mail(), which I provided the link for in my first answer then that provides pretty well everything you need - see the "User Comments" after the official documentation, too. Also check out RFC822 (http://www.faqs.org/rfcs/rfc822.html is one place where it's hosted), which provides valid e-mail headers.

Sunil
0
 
DonkadelicsAuthor Commented:
It's seems complicated, you can forget about the CC field because it's not so important.
Can you try and fix up the attachment method after you have finish your exam?
Many thanks and good luck!
It's OK if I wait until another week for a response.
0
 
iamanindianCommented:
Well..if you want to use a mail component the way ASPMail works...why not try "http://phpmailer.sourceforge.net"? They provide a class...which allow you to do just anything that you want to...by calling the methods (i.e. Object->Method).

E.g.
require("class.phpmailer.php"); //You include the class

$mail = new PHPMailer(); //create the object

$mail->From     = "list@mydomain.com"; //load the variables
$mail->FromName = "List manager";
$mail->Host     = "smtp1.site.com;smtp2.site.com";
$mail->Mailer   = "smtp";

etc.

Attachments can be added like:

$mail->AddAttachment($path,$name,$encoding,$type);

You will find enough help/documentation/tutorial on the above mentioned site.

Hope this helps.
Regards
WC
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now