简体   繁体   English

如何通过单击按钮发送自动电子邮件?

[英]How to send an automatic email at a click of a button?

I'm creating a page with 4 buttons (the buttons will be 4 different images), so when you press any one of the buttons, an email is sent to the appropriate department. 我正在创建一个包含4个按钮的页面(这些按钮将是4张不同的图像),因此,当您按任意一个按钮时,都会向相应部门发送一封电子邮件。

For example, button 1 is for Math department, when you press button 1, an email is sent automatically to math@uni.com, press button 2, an email is automatically sent to music@uni.com and so on. 例如,按钮1用于数学系,当您按下按钮1时,电子邮件会自动发送到math@uni.com,按下按钮2,电子邮件会自动发送到music@uni.com,依此类推。

This project will be using a subdomain on my work's website eg xxx.ourcompany.com How can I send an email automatically with a click of one of the four buttons using html, php or javascript if necessary? 该项目将使用我工作网站上的子域,例如xxx.ourcompany.com。如果需要,如何通过单击四个按钮之一使用html,php或javascript自动发送电子邮件?

(Ignore below if you have better ideas on how to do the task above, or it would be great if you could help me on the below issue) this is what I've found so far: (如果您对如何完成上述任务有更好的想法,请忽略下面的内容,或者如果您可以在以下问题上为我提供帮助,那就太好了)这就是我到目前为止发现的内容:

I saw a post that someone suggested the code below. 我看到一个帖子,有人在下面建议了代码。 I tried to duplicate the code for four buttons, but the email can't be sent to every mail address from the subdomain (xxx.ourcompany.com). 我试图复制四个按钮的代码,但是无法将电子邮件从子域(xxx.ourcompany.com)发送到每个邮件地址。

Issue: The only email address is receiving the notification is an email address with our company's name in it eg name@ourcompany.com but not yahoo or gmail account. 问题:唯一收到该通知的电子邮件地址是带有我们公司名称的电子邮件地址,例如name@ourcompany.com,但没有yahoo或gmail帐户。 I'm not sure what the reason is? 我不确定是什么原因? Also what is a good way to stop spam as well? 还有什么是阻止垃圾邮件的好方法呢? Your help is really appreciated. 非常感谢您的帮助。

<form action="" method="post">
<input type="submit" value="Send details to A" />
<input type="hidden" name="button_a" value="1" />
</form>

<?php

if(isset($_POST['button_a']))
{

$to      = 'name@ourcompany.com'; //can receive notification

$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@ourcompany.com' . "\r\n" .
    'Reply-To: webmaster@ourcompany.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

echo 'Email Sent.';
}

?>

I duplicate the code for the second button, but the yahoo or gmail email address can't receive notification 我复制了第二个按钮的代码,但是yahoo或gmail电子邮件地址无法收到通知

<form action="" method="post">
<input type="submit" value="Send details to B" />
<input type="hidden" name="button_b" value="1" />
</form>

<?php

if(isset($_POST['button_b']))
{

$to      = 'name@yahoo.com'; //can't receive notification!

$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@ourcompany.com' . "\r\n" .
    'Reply-To: webmaster@ourcompany.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

echo 'Email Sent.';
}

?>

First of all, your emails are considered spam. 首先,您的电子邮件被视为垃圾邮件。 Web mail providers like Gmail and Yahoo only receive email if they think the source is trustworthy. 像Gmail和Yahoo这样的网络邮件提供商仅在认为来源可信赖的情况下才接收电子邮件。 i get that a lot of times, when a co-worker emails me to my personal email using his company email. 当同事用他的公司电子邮件将我发送给我的个人电子邮件时,我得到了很多次。 it always ends up in the spam. 它总是以垃圾邮件结尾。

and consider that your page is online, anyone can hack into it, and send spam all over your company using those one-click emailers you're trying to create. 并认为您的页面处于在线状态,任何人都可以入侵该页面,并使用您要创建的一键式电子邮件向您的公司范围内发送垃圾邮件。

how about concentrating on building sort of inter-department messaging system. 如何集中精力构建部门间消息传递系统。 you'd have to enforce the departments to subscribe to this, maybe build a desktop app or web app for it so they see the messages easily. 您必须强制部门来订阅此消息,可能为此构建一个桌面应用程序或Web应用程序,以便他们轻松查看消息。 it's better this way, sort of an "in-house twitter". 最好用这种方式,例如“内部Twitter”。

or use twitter instead! 或改用Twitter! :D :d

or, i think this is possible, use an email client, and one company email. 或者,我认为这是可能的,请使用电子邮件客户端和一封公司电子邮件。 i think email clients today have "templates". 我认为今天的电子邮件客户端具有“模板”。

The problem might be that you are trying to send an email from a server that's not trusted by gmail or yahoo et al. 问题可能是您正在尝试从不受gmail或yahoo等人信任的服务器发送电子邮件。 Check the spam folders. 检查垃圾邮件文件夹。 Some e-mails don't even get to the spam folders. 有些电子邮件甚至没有进入垃圾邮件文件夹。

The header was not specified as array. 标头未指定为数组。 Keep a dot in between header and equals sign. 在标题和等号之间保留一个点。 Example 4 of this page works like charm 此页面的示例4就像魅力

http://php.net/manual/en/function.mail.php http://php.net/manual/en/function.mail.php

As told anyways the email will be considered as spam and the receiver need to update its not a spam. 不管怎么说,该电子邮件将被视为垃圾邮件,收件人需要更新而不是垃圾邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM