我对php很新,但是我有一些使用c#java和vb的经验。我从我的网站写了一个简单的联系表格,它会向我发送一封电子邮件,并向用户发送一封确认电子邮件。这工作得很好。现在我想将此人的姓名和电子邮件地址添加到数据库中以备将来邮寄。如果我要在java或c#中执行此操作,这两个活动将被拆分为2个或更多的类,以便在需要发送电子邮件或添加到数据库的其他情况下使用。这可能在PHP中,或者我应该只是把它写在一个文件中?是否可以从另一个PHP脚本中调用?
谢谢! (编辑),这里的一些代码,我写道:
<?php
$to = "[email protected]";
$subject = "New Contact";
$message = "A new contact named : " . $_POST["fname"] . " " . $_POST["lname"] . "\n" . "has written you a message:" . "\n" . "\n" . $_POST["comment"];
$from = ($_POST["email"]);
mail($to,$subject,$message,"From" . " " . $_POST["email"]);
echo "<p> Thank you for your time helping me to build a better website!</p> <br/> <p> You will recieve an email confirmation shortly </p> <br/> <p> You will be redirected in 5 seconds</p>" ;
$return_message = "Thank you for your comments and suggestions. \n If you required further assistance I will be with you shortly. \n \n Yours, \n \n Craig A. Smith \n \n Original Message: \n" . $_POST["comment"];
mail($from,"Thank You!",$return_message);
?>
这是用户点击提交后,即运行该脚本。 (也有一些确认,以确保所有字段都已填写)
如何将联系表单中的信息发送到将添加到数据库的下一个脚本?我可以很容易地把它写在一个脚本中,但这个网站是我第一次使用php,并且是我的主页,我将在我的简历上做广告。我刚刚离开学校时正在寻找工作。
如果你认为你可能会再次需要它,这是一个好主意,把它放在不同的类,检查http://php.net/manual/en/language.oop5.autoload.php尽管你也可以手动包含你的文件:http:///php.net/manual/en/function.include.php。 – jeroen 2013-03-08 00:24:51
真的没有必要为此写一个类。您应该使用数据库类,但添加该联系人可以用一个简单的函数。 – Popnoodles 2013-03-08 00:27:52
请尝试http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/ – 2013-03-08 00:28:17