FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


SendMail Script





solomagos
HI! I want to place a sript in my webpage so that visitors can email me directly from a HTML page or a PHP page (I mean, just typing in the browser). I have useful php scripts but no one of them allows attachments to be sent to me. So, please, if you know a script that works (specially with FriHost), let me know. I'm desesperated! Been hours and hours surfing with no good results!

Please help me!

Thanks a lot.

Lena.
dandelion
It is not hard to write the script you need from scratch. Please see below for an example.
Code:
<?
  $to = 'you@example.com';
  if (!empty($_POST)) {
    mail(
      $_POST['to'],
      $_POST['subject'],
      $_POST['message'],
      'From: '.$_POST['from']
    );
  }
?>

<form action="<?=$_SERVER['SCRIPT_NAME']?>" method="post">
<input type="text" name="from" value="[Enter your valid email here]" /><br />
<input type="text" name="subject" value="[Enter subject here]" /><br />
<textarea name="message">[Enter your message here]</textarea><br />
<input type="submit" /> <input type="reset" />
</form>

If you need further explanation feel free to ask questions.
SystemWisdom
@dandelion:

You should read his entire post before replying, and you would have noticed he was asking for a script that can send attachments with the message..

@solomagos:
There is a good article on SitePoint that covers Advanced Email with PHP, and includes sending email with attachments.. you should check it out at the following link: http://www.sitepoint.com/article/advanced-email-php
dandelion
SystemWisdom wrote:
@dandelion:

You should read his entire post before replying, and you would have noticed he was asking for a script that can send attachments with the message..

[...]

Thank you for your remark, I really should be more attentive. Embarassed
Anyway, my example is just a start point and can be easily expanded if needed.
I guess writing raw code to send an attacment from scratch is quiet complicated, so I would like to strongly recommend using the PEAR::Mail and PEAR::Mail_Mime packages (installation required).
Code:
<?
  $to = 'you@example.com';

  require_once 'Mail.php';
  require_once 'Mail/mime.php';

  if (!empty($_POST)) {
    $headers = array(
      'Subject' => $_POST['subject'],
      'From' => $_POST['from']
    );
    $mime = new Mail_mime();
    $mime->setTxtBody($_POST['message']);
    if (isset($_FILES['attachment']['tmp_name'])) {
      $mime->addAttachment($_FILES['attachment']['tmp_name']);
    }
    $mime_message = $mime->get();
    $mime_headers = $mime->headers($headers);
    $mailer =& Mail::factory('mail');
    $mailer->send($to, $mime_headers, $mime_message);
  }
?>

<form action="<?=$_SERVER['SCRIPT_NAME']?>" method="post" enctype="multipart/form-data">
<input type="text" name="from" value="[Enter your valid email here]" /><br />
<input type="text" name="subject" value="[Enter subject here]" /><br />
<textarea name="message">[Enter your message here]</textarea><br />
<input type="file" name="attachment" /><br />
<input type="submit" /> <input type="reset" />
</form>

To make yourself entirely happy you might also rewrite the form with the PEAR::HTML_QuickForm package adding some validation rules. Very Happy
solomagos
Thak you very much SystemWisdom! It worked at last! Very Happy Very Happy I'm sooooo happy now. But there's one more thing, that script only allows one attachment to be sent. I've tried myself to modify the script so that it sends to attachments, but it didn't work. Sad Anyway, if anyone wants to send me more than one att, he/she can send several emails, and done! Laughing Well thank you a lot for the help!

Twisted Evil Lena Twisted Evil

P.S: Actually, i'm a girl, so i'm not 'he'. Wink
dandelion
solomagos wrote:
...But there's one more thing, that script only allows one attachment to be sent. I've tried myself to modify the script so that it sends to attachments, but it didn't work...


It is easy with PEAR. Wink
All you need is just a few extra lines in code above:
Code:
<?
    if (isset($_FILES['attachment_1']['tmp_name'])) {
      $mime->addAttachment($_FILES['attachment_1']['tmp_name']);
    }
    if (isset($_FILES['attachment_2']['tmp_name'])) {
      $mime->addAttachment($_FILES['attachment_2']['tmp_name']);
    }
    if (isset($_FILES['attachment_3']['tmp_name'])) {
      $mime->addAttachment($_FILES['attachment_3']['tmp_name']);
    }
?>

and
Code:
<input type="file" name="attachment_1" /><br />
<input type="file" name="attachment_2" /><br />
<input type="file" name="attachment_3" /><br />
Related topics
Which is your favourite weblog Script?
Chat script
Script Upload (obiefileman)
script backup database
Script run background
Can someone make me a php script?
target = _parent redirect script?
Bookmark Script:
Some Script Show
Form Sending and Something else
Looking for easy FormMail Script
Problem with sendmail
Fantastic form creator program
wierd php problem with sendmail
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.