简体   繁体   English

如何在MVC C#应用程序上将php作为帖子执行?

[英]How can I execute php as an post on a MVC C# application?

I have a simple C# asp.net MVC5 project with some bootstrap and other fancy css plugins. 我有一个简单的C#asp.net MVC5项目,其中包含一些引导程序和其他精美的CSS插件。

I have little experience with this so I may have missed some basic logic. 我对此经验很少,所以我可能错过了一些基本逻辑。

So I have this fancy php that will send a styled e-mail to our customers. 所以我有这个花哨的php,它将向我们的客户发送一封样式化的电子邮件。

The way the view is set up is like this: 视图的设置方式如下:

<form (...) method="post" action="sendemail.php">

As you can see, it really does not make sence to post to "sendemail.php" in a C# MVC application. 如您所见,在C#MVC应用程序中确实没有必要发布到“ sendemail.php”。

I do, however, want to use the logic set in sendemail.php to send this email. 但是,我确实想使用sendemail.php中设置的逻辑来发送此电子邮件。 I am not able to map in the sendemail.php to a controller/view (because it only(?) accepts .cshtml). 我无法将sendemail.php中的内容映射到控制器/视图(因为only(?)接受.cshtml)。

Anyone have any ideas how I can do this? 有人有任何想法我该怎么做吗?

This is the complete code in the form on the Contact.cshtml file: 这是Contact.cshtml文件上形式的完整代码:

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                <div class="col-sm-5 col-sm-offset-1">
                    <div class="form-group">
                        <label>Name *</label>
                        <input type="text" name="name" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Email *</label>
                        <input type="email" name="email" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Phone</label>
                        <input type="number" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Company Name</label>
                        <input type="text" class="form-control">
                    </div>                        
                </div>
                <div class="col-sm-5">
                    <div class="form-group">
                        <label>Subject *</label>
                        <input type="text" name="subject" class="form-control" required="required">
                    </div>
                    <div class="form-group">
                        <label>Message *</label>
                        <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                    </div>                        
                    <div class="form-group">
                        <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                    </div>
                </div>
            </form> 

This is very simple, because after all it is all about a POST request. 这很简单,因为毕竟这都是关于POST请求的。

It does not matter what the post server side programming language is. 后服务器端编程语言是什么都没有关系。

Simply post your request to the PHP script, then redirect it back to your MVC application. 只需将您的请求发布到PHP脚本,然后将其重定向回您的MVC应用程序。

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

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